Apr 02, 2020 Because C allows overloading, you can call overloads of sqrt that take float or long double types. In a C program, sqrt always takes and returns double. By default, this function's global state is scoped to the application. To change this, see Global state in the CRT. Return Value. The sqrt functions return the square-root of x. C program to find Square Root of a Number For calculate Square Root of a number we multiply number by 0.5 because square root of any number means power of 1/2 and 1/2=0.5. And one another method for this program is use sqrt function it is pre-defined in math.h header file.
< c | numeric | math
CLanguage | ||||
Headers | ||||
Type support | ||||
Program utilities | ||||
Variadic function support | ||||
Error handling | ||||
Dynamic memory management | ||||
Date and time utilities | ||||
Strings library | ||||
Algorithms | ||||
Numerics | ||||
Input/output support | ||||
Localization support | ||||
Atomic operations(C11) | ||||
Thread support(C11) | ||||
Technical Specifications |
Common mathematical functions | ||||
Floating-point environment(C99) | ||||
Complex number arithmetics(C99) | ||||
Random number generation | ||||
Type-generic math(C99) |
Functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Basic operations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Exponential functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Power functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Trigonometric and hyperbolic functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Error and gamma functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Nearest integer floating point operations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Floating point manipulation functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Classification | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Types | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Macro constants | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
float sqrtf(float arg ); | (1) | (since C99) |
(2) | ||
longdouble sqrtl(longdouble arg ); | (3) | (since C99) |
#define sqrt( arg ) | (4) | (since C99) |
4) Type-generic macro: If
arg
has type longdouble, sqrtl
is called. Otherwise, if arg
has integer type or the type double, sqrt
is called. Otherwise, sqrtf
is called. If arg
is complex or imaginary, then the macro invokes the corresponding complex function (csqrtf, csqrt, csqrtl).[edit]Parameters
arg | - | floating point value |
Sqrt Function In Dev C 2017
[edit]Return value
![Sqrt Function In Dev C++ Sqrt Function In Dev C++](/uploads/1/2/6/2/126290796/367260526.jpg)
If no errors occur, square root of
arg
(√arg), is returned.If a domain error occurs, an implementation-defined value is returned (NaN where supported).
If a range error occurs due to underflow, the correct result (after rounding) is returned.
[edit]Error handling
Errors are reported as specified in math_errhandling.
Domain error occurs if
arg
is less than zero.If the implementation supports IEEE floating-point arithmetic (IEC 60559),
- If the argument is less than -0, FE_INVALID is raised and NaN is returned.
- If the argument is +∞ or ±0, it is returned, unmodified.
- If the argument is NaN, NaN is returned
[edit]Notes
sqrt
is required by the IEEE standard to be exact. The only other operations required to be exact are the arithmetic operators and the function fma. After rounding to the return type (using default rounding mode), the result of sqrt
is indistinguishable from the infinitely precise result. In other words, the error is less than 0.5 ulp. Other functions, including pow, are not so constrained.[edit]Example
Possible output:
[edit]References
- C11 standard (ISO/IEC 9899:2011):
- 7.12.7.5 The sqrt functions (p: 249)
- 7.25 Type-generic math <tgmath.h> (p: 373-375)
- F.10.4.5 The sqrt functions (p: 525)
- C99 standard (ISO/IEC 9899:1999):
- 7.12.7.5 The sqrt functions (p: 229-230)
- 7.22 Type-generic math <tgmath.h> (p: 335-337)
- F.9.4.5 The sqrt functions (p: 462)
- C89/C90 standard (ISO/IEC 9899:1990):
- 4.5.5.2 The sqrt function
[edit]See also
(C99)(C99) | computes a number raised to the given power (xy) (function)[edit] |
(C99)(C99)(C99) | computes cubic root (3√x) (function)[edit] |
(C99)(C99)(C99) | computes square root of the sum of the squares of two given numbers (√x2 +y2 ) (function)[edit] |
(C99)(C99)(C99) | computes the complex square root (function)[edit] |
Retrieved from 'https://en.cppreference.com/mwiki/index.php?title=c/numeric/math/sqrt&oldid=114669'
-->Calculates the square root.
Syntax
Parameters
x
Non-negative floating-point value
Non-negative floating-point value
Remarks
Sqrt Function In Dev C 4
Because C++ allows overloading, you can call overloads of sqrt that take float or longdouble types. In a C program, sqrt always takes and returns double.
By default, this function's global state is scoped to the application. To change this, see Global state in the CRT.
Return Value
The sqrt functions return the square-root of x. By default, if x is negative, sqrt returns an indefinite NaN.
Sqrt Function In C
Input | SEH Exception | _matherr Exception |
---|---|---|
± QNAN,IND | none | _DOMAIN |
- ∞ | none | _DOMAIN |
x<0 | none | _DOMAIN |
Requirements
Function | C header | C++ header |
---|---|---|
sqrt, sqrtf, sqrtl | <math.h> | <cmath> |
For compatibility information, see Compatibility.
Example
See also
Floating-Point Support
exp, expf, expl
log, logf, log10, log10f
pow, powf, powl
_CIsqrt
exp, expf, expl
log, logf, log10, log10f
pow, powf, powl
_CIsqrt