float cbrtf( float arg );
(1) (since C99)double cbrt( double arg );
(2) (since C99)long double cbrtl( long double arg );
(3) (since C99)#define cbrt( arg )
(4) (since C99)1-3) Computes the cube root of arg
.
4) Type-generic macro: If arg
has type long double, cbrtl
is called. Otherwise, if arg
has integer type or the type double, cbrt
is called. Otherwise, cbrtf
is called.
If no errors occur, the cube root of arg
(\(\small{\sqrt[3]{arg} }\)3âarg), is returned.
If a range error occurs due to underflow, the correct result (after rounding) is returned.
[edit] Error handlingErrors are reported as specified in math_errhandling.
If the implementation supports IEEE floating-point arithmetic (IEC 60559),
is not equivalent to
pow(arg, 1.0/3)because the rational number
\(\small{\frac1{3} }\)is typically not equal to
1.0/3and
std::powcannot raise a negative base to a fractional exponent. Moreover,
cbrt(arg)usually gives more accurate results than
pow(arg, 1.0/3)(see example).
[edit] Example#include <float.h> #include <math.h> #include <stdio.h> int main(void) { printf("Normal use:\n" "cbrt(729) = %f\n", cbrt(729)); printf("cbrt(-0.125) = %f\n", cbrt(-0.125)); printf("Special values:\n" "cbrt(-0) = %f\n", cbrt(-0.0)); printf("cbrt(+inf) = %f\n", cbrt(INFINITY)); printf("Accuracy:\n" "cbrt(343) = %.*f\n", DBL_DECIMAL_DIG, cbrt(343)); printf("pow(343,1.0/3) = %.*f\n", DBL_DECIMAL_DIG, pow(343, 1.0/3)); }
Possible output:
Normal use: cbrt(729) = 9.000000 cbrt(-0.125) = -0.500000 Special values: cbrt(-0) = -0.000000 cbrt(+inf) = inf Accuracy: cbrt(343) = 7.00000000000000000 pow(343,1.0/3) = 6.99999999999999911[edit] References
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4