Ruby | Math frexp() function

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

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.