Elemental Intrinsic Function (Generic): Produces the square root of its argument.
Syntax
result = SQRT (x)
x
(Input) must be of type real or complex. If x is type real, its value must be greater than or equal to zero.
Results
The result type is the same as x. The result has a value equal to the square root of x. A result of type complex is the principal value, with the real part greater than or equal to zero. When the real part of the result is zero, the imaginary part is greater than or equal to zero.
Specific Name | Argument Type | Result Type |
---|---|---|
SQRT | REAL(4) | REAL(4) |
DSQRT | REAL(8) | REAL(8) |
QSQRT | REAL(16) | REAL(16) |
CSQRT 1 | COMPLEX(4) | COMPLEX(4) |
CDSQRT 2 | COMPLEX(8) | COMPLEX(8) |
CQSQRT | COMPLEX(16) | COMPLEX(16) |
1 The setting of compiler options specifying real size can affect CSQRT. 2 This function can also be specified as ZSQRT. |
Examples
SQRT (16.0) has the value 4.0.
SQRT (3.0) has the value 1.732051.
The following shows another example:
! Calculate the hypotenuse of a right triangle
! from the lengths of the other two sides.
REAL sidea, sideb, hyp
sidea = 3.0
sideb = 4.0
hyp = SQRT (sidea**2 + sideb**2)
WRITE (*, 100) hyp
100 FORMAT (/ ' The hypotenuse is ', F10.3)
END