Calculate.framework

From iPhone Development Wiki
Jump to: navigation, search
Calculate.framework
Private Framework
Availabile 2.0 – present


The Calculate framework provides a single function, CalculatePerformExpression, whose only purpose is to evaluate a mathematical expression in a string. The usage as same as the Mac OS X counterpart, and is documented in [1].

Recognized expressions

  • Binary operators:
    • and, or, nor, xor, +, -, *, /, <<, >>
  • Constants:
    • pi
  • Unary functions:
    • sqrt, cbrt, exp, ln, log, sin, cos, tan, asin, acos, atan, sind, cosd, tand, asind, acosd, atand, sinh, cosh, tanh, asinh, acosh, atanh, ceil, floor, fabs, rint, lgamma, erf, erfc
  • Binary functions:
    • pow, fmod, hypot, rem
  • Miscellaneous:
    • x! (factorial), -x (unary minus)

Changing mode and precision in "runtime"

The evaluation mode can be changed in runtime with the integer, double and decimal keyword, e.g.

  • integer 8/3 (returns 2)

The precision can be changed in runtime with precision=x, where 0 ≤ x ≤ 16.

Header