HYPOT(3) - [MATHEMATICS] Returns the Euclidean distance - the distance between a point and the origin.
result = hypot(x, y)
elemental real(kind=KIND) function hypot(x,y)real(kind=KIND),intent(in) :: x real(kind=KIND),intent(in) :: y
o X,Y and the result shall all be real and of the same KIND.
HYPOT(3) is referred to as the Euclidean distance function. It is equal to
sqrt(x**2+y**2)without undue underflow or overflow.
In mathematics, the Euclidean distance between two points in Euclidean space is the length of a line segment between two points.
HYPOT(X,Y) returns the distance between the point <X,Y> and the origin.
o X : The type shall be real. o Y : The type and kind type parameter shall be the same as X.
The return value has the same type and kind type parameter as X.
The result is the positive magnitude of the distance of the point <X,Y> from the origin <0.0,0.0> .
Sample program:
program demo_hypot use, intrinsic :: iso_fortran_env, only : & & real_kinds, real32, real64, real128 implicit none real(kind=real32) :: x, y real(kind=real32),allocatable :: xs(:), ys(:) integer :: i character(len=*),parameter :: f=(a,/,SP,*(3x,g0,1x,g0:,/))Results:x = 1.e0_real32 y = 0.5e0_real32
write(*,*) write(*,(*(g0)))point <,x,,,y,> is ,hypot(x,y) write(*,(*(g0)))units away from the origin write(*,*)
! elemental xs=[ x, x**2, x*10.0, x*15.0, -x**2 ] ys=[ y, y**2, -y*20.0, y**2, -y**2 ]
write(*,f)"the points",(xs(i),ys(i),i=1,size(xs)) write(*,f)"have distances from the origin of ",hypot(xs,ys) write(*,f)"the closest is",minval(hypot(xs,ys))
end program demo_hypot
point <1.00000000,0.500000000> is 1.11803401 units away from the originthe points +1.00000000 +0.500000000 +1.00000000 +0.250000000 +10.0000000 -10.0000000 +15.0000000 +0.250000000 -1.00000000 -0.250000000 have distances from the origin of +1.11803401 +1.03077638 +14.1421356 +15.0020828 +1.03077638 the closest is +1.03077638
Fortran 2008
****(3)
fortran-lang intrinsic descriptions (license: MIT) @urbanjost
Nemo Release 3.1 | hypot (3fortran) | April 28, 2024 |