On this page
sqrt
Prev: math.h | Up: math.h | Next: fabs
Rel: math.h, math, time & assert Guide
Ref: cppreference — sqrt
Tags: #public #prog #c #stdlib #math #tier/core
Include
#include <math.h>
Signature & Overview
double sqrt(double x); /* also sqrtf, sqrtl */
Computes the non-negative square root of x (returns NaN and sets EDOM if x < 0).
Notes & Pitfalls
- Negative inputs return
NaNand setEDOM: Checkx >= 0.0before callingsqrt(x).
Example
#include <assert.h>
#include <math.h>
int main(void) { assert(fabs(sqrt(25.0) - 5.0) < 1e-9); }
Linked from
Related notes
- tuts/c/stdlib/math/fabs Linked here; links to this page; shared tags: #c, #math, #prog, #stdlib, #tier
- tuts/c/stdlib/math Linked here; links to this page; shared tags: #c, #math, #prog, #stdlib
- tuts/c/stdlib/math_time_and_assert Linked here; shared tags: #c, #prog, #stdlib
- tuts/c/stdlib/math/floor shared tags: #c, #math, #prog, #stdlib, #tier
- tuts/c/stdlib/math/isnan shared tags: #c, #math, #prog, #stdlib, #tier
- tuts/c/stdlib/math/pow shared tags: #c, #math, #prog, #stdlib, #tier
- tuts/c/stdlib/assert/assert shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/assert/static_assert shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/ctype/isalpha shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/ctype/isdigit shared tags: #c, #prog, #stdlib, #tier