Math Functions

math.log2()

Compute a base-two logarithm of a positive number.

Formal Syntax & Structure

python syntaxpython
math.log2(x, /)

Parameters & Attributes

NameTypeDescription
xreal numberInput real value.

Return Value

float

Floating-point result; finite precision and domain restrictions apply.

Working Example

Example Snippetpython
import mathprint(math.log2(128))
Python Reference