Skip to content

Modern Math Log2

Paul Squires edited this page Oct 19, 2026 · 1 revision

Home › Math Library › Math Library › Log2

Log2

Returns the base-2 logarithm of a number.

Syntax

Log2( x )

Notes

  • Exact for a power of two.
  • 0 gives minus infinity and a negative number gives NaN.
  • Overloaded on float64 and on float32: a single-precision argument takes the single-precision path and does not widen.
  • BOUNDED accuracy: correct to the platform library's stated ulp bound.

Examples

#import "std/numeric"
using numeric

print Log2( 1024.0 )         '' 10
print Log2( 3.0 )            '' 1.584962500721156
print Log2( 0.0 )            '' -1.#INF

Library: Math Library
Category: Math Library
Documented under: The libm surface

Clone this wiki locally