Rate This Document
Findability
Accuracy
Completeness
Readability

hypot

Compute the square root of (x^2 + y^2), where x and y are real numbers.

Interface Definition

C interface:

float hypotf(float x, float y);

double hypot(double x, double y);

long double hypotl(long double x, long double x);

Parameters

Parameter

Type

Description

Input/Output

x

  • For hypotf, x is of single-precision floating-point type.
  • For hypot, x is of double-precision floating-point type.
  • For hypotl, x is of long double-precision floating-point type.

Floating-point value of the input data.

Input

y

  • For hypotf, y is of single-precision floating-point type.
  • For hypot, y is of double-precision floating-point type.
  • For hypotl, y is of long double-precision floating-point type.

Floating-point value of the input data.

Input

Return Value

  • The square root of (x^2 + y^2) is returned. x ∈ (-INF, +INF); y ∈ (-INF, +INF)
  • If input x or y is ±inf, the return value is inf.
  • If input x or y is NaN, the return value is NaN.
  • If the square root of (x^2 + y^2) is greater than inf, the return value is inf. (Note that the corresponding function at Intel may return NaN in some cases.)

Dependency

C: "km.h"

Example

C interface:

    // typical usage
    float x1 = 3.0, x2 = 0x1.fp127;
    float y1 = 4.0, y2 = -0x1p70;
    // special handling
    float e = INFINITY, f = -INFINITY, g = NAN;
    // print result
    printf("hypotf(3.0, 4.0) = %.15f\n", hypotf(x1, y1));
    printf("hypotf(0x1.fp127, 0x1.fp127) = %.15f\n", hypotf(x2, x2));
    printf("hypotf(-0x1p70, -0x1p70) = %.15f\n", hypotf(y2, y2));
    printf("hypotf(INFINITY, 0) = %.15f\n", hypotf(e, 0.0f));
    printf("hypotf(-INFINITY, 3.0) = %.15f\n", hypotf(f, x1));
    printf("hypotf(NAN, 3.0) = %.15f\n", hypotf(g, x1));
    printf("hypotf(NAN, INFINITY) = %.15f\n", hypotf(g, e));
    /* 
     * hypotf(3.0, 4.0) = 5.000000000000000
     * hypotf(0x1.fp127, 0x1.fp127) = inf
     * hypotf(-0x1p70, -0x1p70) = 1669608653068460621824.000000000000000
     * hypotf(INFINITY, 0) = inf
     * hypotf(-INFINITY, 3.0) = inf
     * hypotf(NAN, 3.0) = nan
     * hypotf(NAN, INFINITY) = inf
     * 
     * */