← All notes

math: real-valued math functions and constants

Answer: These functions cannot be used with complex numbers; cmath is the module for that. The math module provides common mathematical functions and constants, including those from the C standard. Most return values are floats. Constants include pi, e, tau, inf, and nan.

Real functions, not complex

math is the standard-library entry point for common mathematical functions and constants, including the ones defined by the C standard.

These functions cannot be used with complex numbers. If you need complex support, use the same names in the cmath module.

The docs explain the split: most users do not want to learn quite as much mathematics as complex numbers require.

Except when the docs say otherwise, all return values are floats.

Ceiling, floor, and constants

ceil(x) is the ceiling of x: the smallest integer greater than or equal to x.

floor(x) is the floor of x: the largest integer less than or equal to x.

fabs(x) returns the absolute value of x.

Listed constants include pi, e, tau (2π), inf for positive infinity, and nan for “Not a number”.

The source documentation

The library source documentation also says these functions cannot be used with complex numbers if you require support for complex numbers from the cmath module.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, math — Mathematical functions; CPython, math module documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, math — Mathematical functions; CPython, math module documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.

Cite this

Permanent ID: iil:note:8krna8xc

iinventedlight. 2026. "math: real-valued math functions and constants." iinventedlight Library, iil:note:8krna8xc, version of 2026-11-23. https://iinventedlight.com/library/notes/python-math/. License: CC-BY-4.0.

@misc{iil_note_8krna8xc,
  author = {{iinventedlight}},
  title = {{math: real-valued math functions and constants}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-23},
  url = {https://iinventedlight.com/library/notes/python-math/},
  note = {Permanent ID iil:note:8krna8xc. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-math.md.