Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

Math.log2

Math.log2(x) → Float

Returns the base 2 logarithm of x.

Domain: (0, INFINITY)

Codomain: (-INFINITY, INFINITY)

Example
Math.log2(1)      #=> 0.0
Math.log2(2)      #=> 1.0
Math.log2(32768)  #=> 15.0
Math.log2(65536)  #=> 16.0
See also .log10 .sin .log .sinh also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0