cppreference.com
Create account Namespaces
Variants
Views
Actions
cbrt, cbrtf, cbrtl From cppreference.com
< c | numeric | math C
| Compiler support |
| Language |
| Headers |
| Type support |
| Program utilities |
| Variadic function support |
| Error handling |
| Dynamic memory management |
| Strings library |
| Algorithms |
| Numerics |
| Date and time utilities |
| Input/output support |
| Localization support |
| Concurrency support (C11) |
| Technical Specifications |
| Symbol index |
[edit] Numerics
| Common mathematical functions |
| Floating-point environment (C99) |
| Pseudo-random number generation |
| Complex number arithmetic (C99) |
| Type-generic math (C99) |
| Bit manipulation (C23) |
| Checked integer arithmetic (C23) |
[edit] Common mathematical functions
| Functions | | Basic operations | | abslabsllabsimaxabs(C99)(C99) | | fabs | | divldivlldivimaxdiv(C99)(C99) | | | fmod | | remainder(C99) | | remquo(C99) | | fma(C99) | | fdim(C99) | | nannanfnanlnandN(C99)(C99)(C99)(C23) | | | Maximum/minimum operations | | fmax(C99) | | fmin(C99) | | fmaximum(C23) | | fminimum(C23) | | fmaximum_mag(C23) | | | fmaximum_num(C23) | | fminimum_mag(C23) | | fminimum_num(C23) | | fmaximum_mag_num(C23) | | fminimum_mag_num(C23) | | | Exponential functions | | exp | | exp10(C23) | | exp2(C99) | | expm1(C99) | | exp10m1(C23) | | exp2m1(C23) | | | log | | log10 | | log2(C99) | | log1plogp1(C99)(C23) | | log10p1(C23) | | log2p1(C23) | | | Power functions | | sqrt | | cbrt(C99) | | rootn(C23) | | rsqrt(C23) | | | hypot(C99) | | compound(C23) | | pow | | pown(C23) | | powr(C23) | | | Trigonometric and hyperbolic functions | | sin | | cos | | tan | | asin | | acos | | atan | | atan2 | | sinpi(C23) | | cospi(C23) | | tanpi(C23) | | | asinpi(C23) | | acospi(C23) | | atanpi(C23) | | atan2pi(C23) | | sinh | | cosh | | tanh | | asinh(C99) | | acosh(C99) | | atanh(C99) | | | | Nearest integer floating-point | | ceil | | floor | | roundlroundllround(C99)(C99)(C99) | | roundeven(C23) | | trunc(C99) | | | nearbyint(C99) | | rintlrintllrint(C99)(C99)(C99) | | fromfpfromfpxufromfpufromfpx(C23)(C23)(C23)(C23) | | | Floating-point manipulation | | ldexp | | frexp | | scalbnscalbln(C99)(C99) | | ilogbllogb(C99)(C23) | | logb(C99) | | | modf | | nextafternexttoward(C99)(C99) | | nextupnextdown(C23)(C23) | | copysign(C99) | | canonicalize(C23) | | | Narrowing operations | | fadd(C23) | | fsub(C23) | | fmul(C23) | | | fdiv(C23) | | ffma(C23) | | fsqrt(C23) | | | Quantum and quantum exponent | | quantizedN(C23) | | quantumdN(C23) | | | samequantumdN(C23) | | llquantexpdN(C23) | | | Decimal re-encoding functions | | encodedecdN(C23) | | decodedecdN(C23) | | | encodebindN(C23) | | decodebindN(C23) | | | Total order and payload functions | | totalorder(C23) | | getpayload(C23) | | | setpayload(C23) | | setpayloadsig(C23) | | | Classification | | fpclassify(C99) | | iscanonical(C23) | | isfinite(C99) | | isinf(C99) | | isnan(C99) | | isnormal(C99) | | signbit(C99) | | issubnormal(C23) | | iszero(C23) | | | isgreater(C99) | | isgreaterequal(C99) | | isless(C99) | | islessequal(C99) | | islessgreater(C99) | | isunordered(C99) | | issignaling(C23) | | iseqsig(C23) | | | | Error and gamma functions | | | | Types | | div_tldiv_tlldiv_timaxdiv_t(C99)(C99) | | | float_tdouble_t(C99)(C99) | | _Decimal32_t_Decimal64_t(C23)(C23) | | | Macro constants | | Special floating-point values | | HUGE_VALHUGE_VALFHUGE_VALLHUGE_VALDN(C99)(C99)(C23) | | | INFINITYDEC_INFINITY(C99)(C23) | | NANDEC_NAN(C99)(C23) | | | Arguments and return values | | FP_ILOGB0FP_ILOGBNAN(C99)(C99) | | FP_NORMALFP_SUBNORMALFP_ZEROFP_INFINITEFP_NAN(C99)(C99)(C99)(C99)(C99) | | | FP_LLOGB0FP_LLOGBNAN(C23)(C23) | | FP_INT_UPWARDFP_INT_DOWNWARDFP_INT_TOWARDZEROFP_INT_TONEARESTFROMZEROFP_INT_TONEAREST(C23)(C23)(C23)(C23)(C23) | | | Error handling | | MATH_ERRNOMATH_ERRNOEXCEPT(C99)(C99) | | | | Fast operation indicators | | FP_FAST_FMAFFP_FAST_FMA(C99)(C99) | | FP_FAST_FADDFP_FAST_FADDLFP_FAST_DADDLFP_FAST_DMADDDN(C23)(C23)(C23)(C23) | | FP_FAST_FMULFP_FAST_FMULLFP_FAST_DMULLFP_FAST_DMMULDN(C23)(C23)(C23)(C23) | | FP_FAST_FFMAFP_FAST_FFMALFP_FAST_DFMALFP_FAST_DMFMADN(C23)(C23)(C23)(C23) | | | FP_FAST_FMALFP_FAST_FMADN(C99)(C23) | | FP_FAST_FSUBFP_FAST_FSUBLFP_FAST_DSUBLFP_FAST_DMSUBDN(C23)(C23)(C23)(C23) | | FP_FAST_FDIVFP_FAST_FDIVLFP_FAST_DDIVLFP_FAST_DMDIVDN(C23)(C23)(C23)(C23) | | FP_FAST_FSQRTFP_FAST_FSQRTLFP_FAST_DSQRTLFP_FAST_DMSQRTDN(C23)(C23)(C23)(C23) | | |
[edit] | Defined in header <math.h> |
| float cbrtf( float arg ); | (1) | (since C99) |
| double cbrt( double arg ); | (2) | (since C99) |
| long double cbrtl( long double arg ); | (3) | (since C99) |
| Defined in header <tgmath.h> |
| #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.
Contents - 1 Parameters
- 2 Return value
- 3 Error handling
- 4 Notes
- 5 Example
- 6 References
- 7 See also
|
[edit] Parameters
| arg | - | floating-point value |
[edit] Return value
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 handling
Errors are reported as specified in math_errhandling.
If the implementation supports IEEE floating-point arithmetic (IEC 60559),
- if the argument is ±0 or ±∞, it is returned, unchanged
- if the argument is NaN, NaN is returned.
[edit] Notes
cbrt(arg) is not equivalent to
pow(arg, 1.0/3) because the rational number
\(\small{\frac1{3} }\) is typically not equal to
1.0/3 and
std::pow cannot 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
Run this code
#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
- C23 standard (ISO/IEC 9899:2024):
- 7.12.7.1 The cbrt functions (p: TBD)
- 7.25 Type-generic math <tgmath.h> (p: TBD)
- F.10.4.1 The cbrt functions (p: TBD)
- C17 standard (ISO/IEC 9899:2018):
- 7.12.7.1 The cbrt functions (p: 180-181)
- 7.25 Type-generic math <tgmath.h> (p: 272-273)
- F.10.4.1 The cbrt functions (p: 381-)
- C11 standard (ISO/IEC 9899:2011):
- 7.12.7.1 The cbrt functions (p: 247)
- 7.25 Type-generic math <tgmath.h> (p: 373-375)
- F.10.4.1 The cbrt functions (p: 524)
- C99 standard (ISO/IEC 9899:1999):
- 7.12.7.1 The cbrt functions (p: 228)
- 7.22 Type-generic math <tgmath.h> (p: 335-337)
- F.9.4.1 The cbrt functions (p: 460)
[edit] See also
| powpowfpowl(C99)(C99) | computes a number raised to the given power (\(\small{x^y}\)xy) (function) [edit] |
| sqrtsqrtfsqrtl(C99)(C99) | computes square root (\(\small{\sqrt{x} }\)√x) (function) [edit] |
| hypothypotfhypotl(C99)(C99)(C99) | computes square root of the sum of the squares of two given numbers (\(\scriptsize{\sqrt{x^2+y^2} }\)√x2+y2) (function) [edit] |
| C++ documentation for cbrt |
Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/numeric/math/cbrt&oldid=172001"
Navigation
- Support us
- Recent changes
- FAQ
- Offline version
Toolbox
- What links here
- Related changes
- Upload file
- Special pages
- Printable version
- Permanent link
- Page information
- العربية
- Česky
- Deutsch
- Español
- Français
- Italiano
- 日本語
- 한국어
- Polski
- Português
- Русский
- Türkçe
- 中文