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

These functions take and return float.

The module defines a RealFuns protocol and implements it for float. The exported module functions delegate through that protocol.