Ruby Tutorial Ruby References

Ruby - Math.ldexp() Method



The Ruby Math.ldexp() method returns the result of multiplying the significand (x) by 2 raised to the power of the exponent (exp), i.e., x * 2exp.

Syntax

Math.ldexp(x, exp)

Parameters

x Specify floating point value representing the significand.
exp Specify value of the exponent.

Return Value

Returns x * 2exp.

Example:

The example below shows the usage of Math.ldexp() function.

sig = 0.625
exp = 4

Num = Math.ldexp(sig, exp)

puts "Significand: #{sig}" 
puts "Exponent: #{exp}" 
puts "Result: #{Num}" 

The output of the above code will be:

Significand: 0.625
Exponent: 4
Result: 10.0

❮ Ruby Math Module