sqrt
Compute the square root of x.
Interface Definition
C interface:
float sqrtf(float x);
double sqrt(double x);
long double sqrtl(long 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 input x is ±0, the return value is ±0.
- If input x is +∞, the return value is +∞.
- If input x is -∞, the return value is NaN.
- If input x is NaN, the return value is NaN.
Dependencies
C: "km.h"
Examples
C interface:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | // typical usage double x1 = 1.0, x2 = 2.0, x3 = 3.0, x4 = 4.0; // special handling 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) = -inf * sqrt(NAN) = nan * */ |
Fortran interface:
REAL(8) :: X = 3.0
PRINT*, SQRT(X)
!
! OUTPUT
! 1.732050807568877
!
Parent topic: Power and Root Functions