Skip to main content

Numbers

  • Integer division truncates: 7 / 2 is 3. Make one side a Real for a fractional result: 7 / 2.0 or n * 1.0 / d.
  • Remainder: there's no %. MathMod(n, d) takes the divisor's sign, so MathMod(-30, 360) is 330 (what wrapping an angle or an index wants). For C's sign-of-n remainder, use n - (n / d) * d.
  • Divide by zero gives 0 and doesn't stop the script. Test the divisor yourself if 0 would be a misleading answer.
  • An Integer becomes a Real when a builtin declares Real. MathSqrt(16) is MathSqrt(16.0). The reverse never happens: a Real passed where an Integer is declared stops the action with argument 1 has the wrong type, so round it first with MathRound, MathFloor or MathCeil.
  • MathAbs, MathMin, MathMax, MathClamp and MathMod take either kind and return the winning argument's own kind (MathMod: Integer only when both are). A tie returns the first argument. MathAtan2(y, x) takes either kind and returns a Real.
  • MathRandom(min, max) is inclusive at both ends, and stops the action if min > max.
  • The Math builtins never return NaN or infinity. A Math builtin given one, or with no finite answer, returns 0 (0.0 when the result is a Real): MathSqrt of a negative number, MathLog of zero or less, a MathPow result that isn't finite, MathFloor, MathCeil or MathRound of NaN. MathFloor, MathCeil and MathRound of a finite value beyond the Integer range give the largest or smallest Integer.
  • Real results show six decimals when turned into Text. Round for display.
  • Trigonometry works in radians: rad = deg * MathGetPi() / 180.
  • Integer arithmetic that goes beyond ±9.2 × 10¹⁸ wraps around to the other end of the range: one more than the largest Integer is the smallest one. There's no error. Keep values in range.