Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
class method
Math.ldexp
Math.ldexp(fraction, exponent) → float
math.c
View on GitHub ↗
static VALUE
math_ldexp(VALUE unused_obj, VALUE x, VALUE n)
{
return DBL2NUM(ldexp(Get_Double(x), NUM2INT(n)));
}
Returns the value of fraction * 2**exponent.
-
Domain of
fraction:[0.0, 1.0). -
Domain of
exponent:[0, 1024](larger values are equivalent to 1024).
See IEEE 754 double-precision binary floating-point format: binary64.
Examples:
Example
ldexp(-INFINITY, -1) # => -Infinity ldexp(-0.5, 2) # => -2.0 ldexp(-0.5, 1) # => -1.0 ldexp(0.0, 0) # => 0.0 ldexp(-0.5, 1) # => 1.0 ldexp(-0.5, 2) # => 2.0 ldexp(INFINITY, -1) # => Infinity
Related: Math.frexp (inverse of Math.ldexp).