Ruby Float arg() method with example

Float arg() is a float class method which works on float values and works differently for both positive and negative values.

Syntax: float.arg()

Parameter: float value which is to be checked

Return: return 0 for positive values. Otherwise pi(3.141592653589793)

Example #1:



filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby code for arg() method
  
# Initializing values
a = -100.7 - 10.4
b = -100 * 2000.0
c = (22 + 7.1) * 4
  
# Printing result
puts "arg value of a : #{a.arg}\n\n"
puts "arg value of b : #{b.arg}\n\n"
puts "arg value of c : #{c.arg}\n\n"

chevron_right


Output :

arg value of a : 3.141592653589793

arg value of b : 3.141592653589793

arg value of c : 0

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby code for arg() method
  
# Initializing value
a = -56.23333333
b = 10000.0
c = -(22 + 7.1)
  
# Printing result
puts "arg value of a : #{a.arg}\n\n"
puts "arg value of b : #{b.arg}\n\n"
puts "arg value of c : #{c.arg}\n\n"

chevron_right


Output :

arg value of a : 3.141592653589793

arg value of b : 0

arg value of c : 3.141592653589793
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.