Related Articles

Related Articles

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

The hypot() function in Ruby returns sqrt(l^2 + b^2) when l and b are given as parameters. It eventually returns the hypotenuse of a right-angled triangle with sides l and b.

Syntax: Math.hypot(l, b)

Parameter: The function takes two mandatory parameter l and b which specifies the length and the base.
Return Value: The function returns the hypotenuse of a right-angled triangle with sides l and b.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for hypot() function 
  
# Assigning values
l1 = 3 
b1 = 4 
  
l2 = 12
b2 = 14
  
# Prints the hypot() value 
puts Math.hypot(l1, b1)
  
puts Math.hypot(l2, b2)

chevron_right


Output:



5.0
18.439088914585774

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for hypot() function 
  
# Assigning values
l1 = 10
b1 = 5
  
l2 = 11
b2 = 20
  
# Prints the hypot() value 
puts Math.hypot(l1, b1)
  
puts Math.hypot(l2, b2)

chevron_right


Output:

11.180339887498949
22.825424421026653

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :