Ruby Tutorial Ruby Resources
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

Ruby - Math.frexp() Method



The Ruby Math.frexp() method is used to break the number x into its binary significand (a floating point with an absolute value in range [0.5, 1.0)) and an integral exponent for 2. Mathematically, it can be expressed as:

x = significand * 2exponent

The method Returns a two-element array containing the significand (a Float) and exponent (an Integer) of x. If x is zero, both significand and exponent are zero. If x is negative, the significand returned by the function is negative.

Syntax

Math.frexp(x)

Parameters

x Specify the value to be decomposed.

Return Value

Returns a two-element array containing the significand (a Float) and exponent (an Integer) of x.

Example:

The example below shows the usage of Math.frexp() method.

Num = 10

#decompose the number
sig, exp = Math.frexp(Num)

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

The output of the above code will be:

Number: 10
Significand: 0.625
Exponent: 4

❮ Ruby Math Module

5