Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. 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 .log1p .sin .log10 .sinh also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0