Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

class method

Math.log2

(::Math::double x) -> ::Float
Math.log2(x) → float

Returns the base 2 logarithm of x.

  • Domain: [0, INFINITY].

  • Range: [-INFINITY, INFINITY].

Examples:

Example
log2(0.0)      # => -Infinity
log2(1.0)      # => 0.0
log2(2.0)      # => 1.0
log2(INFINITY) # => Infinity
See also .log10 .sin .log .sinh also in 4.1 · 4.0 · 3.3 · 3.2 · 3.1 · 3.0