Related Articles

Related Articles

Ruby | Math frexp() function
  • Last Updated : 07 Jan, 2020

The frexp() function in Ruby returns a two-element array containing the normalized fraction which is a float value and an exponent that is an integer value of the given number. On equating, fraction ** (2 ^ exponent) gives back the number.

Syntax: Math.frexp(number)

Parameter: The function takes a mandatory parameter number whose normalised fraction and exponent are to be returned.

Return Value: The function returns a two-element array.

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for frexp() function 
  
# Assigning values
val1 = 123
val2 = 256
val3 = 23
val4 = 18
  
# Prints the frexp() value 
puts Math.frexp(val1)
puts
puts Math.frexp(val2)
puts
puts Math.frexp(val3)
puts
puts Math.frexp(val4) 

chevron_right


Output:

0.9609375
7

0.5
9

0.71875
5

0.5625
5

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for frexp() function 
  
# Assigning values
val1 = 3213
val2 = 12
val3 = 16
val4 = 23
  
# Prints the frexp() value 
puts Math.frexp(val1)
puts
puts Math.frexp(val2)
puts
puts Math.frexp(val3)
puts
puts Math.frexp(val4) 

chevron_right


Output:

0.784423828125
12

0.75
4

0.5
5

0.71875
5

Reference: https://devdocs.io/ruby~2.5/math#method-c-frexp

My Personal Notes arrow_drop_up
Recommended Articles
Page :