sqrt
Compute the square root of x.
Interface Definition
C interface:
float sqrtf(float x);
double sqrt(double x);
Fortran interface:
RES = SQRTF(X);
RES = SQRT(X);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
x |
|
Floating-point value of the input data |
Input |
Return Value
- If x is greater than 0 and y is a decimal, the result of x raised to the power of y is returned. The value range is r ∈ (0, +INF).
- If the input x is ±0, the return value is ±0.
- If the input x is +∞, the return value is +∞.
- If the input x is NaN, the return value is NaN.
Dependencies
C: "km.h"
Fortran: "km.f03"
Examples
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("sqrt(1.0) = %.15f\n", sqrt(x1));
printf("sqrt(2.0) = %.15f\n", sqrt(x2));
printf("sqrt(3.0) = %.15f\n", sqrt(x3));
printf("sqrt(4.0) = %.15f\n", sqrt(x4));
printf("sqrt(0.0) = %.15f\n", sqrt(a));
printf("sqrt(INFINITY) = %.15f\n", sqrt(b));
printf("sqrt(-INFINITY) = %.15f\n", sqrt(c));
printf("sqrt(NAN) = %.15f\n", sqrt(d));
/*
* sqrt(1.0) = 1.000000000000000
* sqrt(2.0) = 1.414213562373095
* sqrt(3.0) = 1.732050807568877
* sqrt(4.0) = 2.000000000000000
* sqrt(0.0) = 0.000000000000000
* sqrt(INFINITY) = inf
* sqrt(-INFINITY) = nan
* sqrt(NAN) = inf
* */
Fortran interface:
REAL(8) :: X = 3.0
PRINT*, SQRT(X)
!
! OUTPUT
! 1.732050807568877
!
Parent topic: KML_MATH Library Functions