Kotlin hypot()
Published Oct 17, 2023
Contribute to Docs
The hypot() method in Kotlin’s math class is used to calculate the hypotenuse of two numbers in a way that avoids overflow and underflow. It returns the square root of the sum of the squares of its two arguments. This is also known as the Euclidean norm of a two-dimensional vector.
Syntax
hypot(x,y)
x: One of the two numbers whose hypotenuse is to be calculated.y: The other number whose hypotenuse is to be calculated.
The hypot() method returns a value of type double. The following are the special cases:
+Infifxoryis infinite.NaNifxoryisNaNand the other is not infinite.
Example
This example shows how to use the hypot() method to calculate the hypotenuse of 3 and 4:
import kotlin.math.*fun main(){println(hypot(3.0,4.0))}
The output of this code will be:
5.0
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Kotlin on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn Kotlin, the expressive, open-source programming language developed by JetBrains.
- Beginner Friendly.9 hours