Rate This Document
Findability
Accuracy
Completeness
Readability

invsqrt

Compute the reciprocal of the square root of x.

Interface Definition

C interface:

float invsqrtf(float x);

double invsqrt(double x);

long double invsqrtl(long double x);

Fortran interface:

RES = SQRTF(X);

RES = SQRT(X);

Parameters

Parameter

Type

Description

Input/Output

x

  • For invsqrtf, x is of single-precision floating-point type.
  • For invsqrt, x is of double-precision floating-point type.
  • For invsqrtl, x is of long double-precision floating-point type.

Floating-point value of the input data.

Input

Return Value

  • If input x is +0, the return value is +∞.
  • If input x is -0, the return value is -∞.
  • If input x is less than 0, the return value is NaN.
  • If input x is +∞, the return value is 0.0.
  • If input x is NaN, the return value is NaN.

Dependency

C: "km.h"

Example

C interface:

    // typical usage 
    double x1 = 1.0, x2 = 2.0, x3 = 3.0, x4 = 4.0; 
    // special handing 
    double a = 0.0, b = INFINITY, c = -INFINITY, d = NAN; 
    // print result 
        printf("invsqrt(1.0) = %.15f\n", invsqrt(x1)); 
        printf("invsqrt(2.0) = %.15f\n", invsqrt(x2)); 
        printf("invsqrt(3.0) = %.15f\n", invsqrt(x3)); 
        printf("invsqrt(4.0) = %.15f\n", invsqrt(x4)); 
        printf("invsqrt(0.0) = %.15f\n", invsqrt(a)); 
        printf("invsqrt(INFINITY) = %.15f\n", invsqrt(b)); 
        printf("invsqrt(-INFINITY) = %.15f\n", invsqrt(c)); 
        printf("invsqrt(NAN) = %.15f\n", invsqrt(d)); 
    /* 
     *  invsqrt(1.0) = 1.000000000000000 
     *  invsqrt(2.0) = 0.707106781186548 
     *  invsqrt(3.0) = 0.577350269189626 
     *  invsqrt(4.0) = 0.500000000000000 
     *  invsqrt(0.0) = inf 
     *  invsqrt(INFINITY) = 0.000000000000000 
     *  invsqrt(-INFINITY) = nan
     *  invsqrt(NAN) = nan 
     * */