Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

hypot, hypotf, hypotl - Euclidean distance

&pagelevel(4)&pagelevel

Definition  

#include <math.h>

double hypot(double x, double y);
float hypotf(float x, float y); (C11)
long double hypotl(long double x, long double y); (C11)

These functions calculate the euclidean distance of the point with the coordinates (x,y).

Return val.

sqrt(x*x + y*y)

square root of the sum of the squared coordinates.


HUGE_VAL
HUGE_VALF  
HUGE_VALL

depending on the function type,in the event of an overflow. In addition, errno is set to ERANGE (result too large).

Example

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main(void)
{
  double x, y, alpha, r, pi;
  printf("Enter x and y coordinates:\n");
  scanf("%lf %lf", &x, &y);
  pi = 2.0 * asin(1.0);
  if(x > 0.0)
    alpha = atan(y/x);
  else if (x < 0.0)
          if (y >= 0.0)
             alpha = atan(y/x) + pi;
          else alpha = atan(y/x) - pi;
       else if (y > 0)
               alpha = pi/2.0;
            else if (y < 0)
                    alpha = -pi/2.0;
                 else
                 {
                   printf("Angle not defined!\n");
                   exit(1);
                 }
  r = hypot(x, y);
  alpha = alpha * (180.0/pi);
  printf("The polar coordinates are:\n");
  printf("Distance from zero: %g\n",r);
  printf("Angle to the x axis:\n");
  printf("%g degrees\n",((y < 0.0)? alpha + 360 : alpha) );
  return 0;
} 

See also

cabs, sqrt