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 - Euklidischer Abstand

&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)

Diese Funktionen berechnen den euklidischen Abstand für den Punkt mit den Koordinaten (x,y).

Returnwert

sqrt(x*x + y*y)

bei Erfolg, d.i. Wurzel aus der Summe der quadrierten Koordinaten.

 

HUGE_VAL
HUGE_VALF
HUGE_VALL

abhängig vom Funktionstyp, bei Überlauf.
Zusätzlich wird errno auf ERANGE gesetzt (Resultat zu groß).

Beispiel

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main(void)
{
  double x, y, alpha, r, pi;
  printf("Koordinaten x und y eingeben:\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("Winkel nicht definiert!\n");
                   exit(1);
                 }
  r = hypot(x, y);
  alpha = alpha * (180.0/pi);
  printf("Die Polarkoordinaten lauten:\n");
  printf("Abstand vom Nullpunkt: %g\n",r);
  printf("Winkel zur x-Achse:\n");
  printf("%g Grad\n",((y < 0.0)? alpha + 360 : alpha) );
  return 0;
}

Siehe auch

cabs, sqrt