Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

math

The math module provides the constant pi and common floating-point functions.

Source:

import math

actor main(env):
    angle = math.pi / 4.0

    print(math.sin(angle))
    print(math.sqrt(9.0))

    env.exit(0)

Import the module first with import math, then call its functions as math.sqrt(...), math.sin(...), and so on.

The module currently exposes:

  • pi
  • sqrt, exp, log
  • sin, cos, tan
  • asin, acos, atan
  • sinh, cosh, tanh
  • asinh, acosh, atanh
  • ldexp(x, exp), which returns x * 2**exp

All functions return float. ldexp also takes an int exponent.