Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      cbrt, cbrtf, cbrtl

      From cppreference.com
      <c‎ |numeric‎ |math
       
       
       
      Common mathematical functions
      Functions
      Basic operations
      (C99)
      (C99)
      (C99)
      (C99)(C99)(C99)(C23)
      Maximum/minimum operations
      (C99)
      (C99)
      Exponential functions
      (C23)
      (C99)
      (C99)
      (C23)
      (C23)

      (C99)
      (C99)(C23)
      (C23)
      (C23)
      Power functions
      cbrt
      (C99)
      (C23)
      (C23)

      (C99)
      (C23)
      (C23)
      Trigonometric and hyperbolic functions
      (C23)
      (C23)
      (C23)
      (C23)
      (C99)
      (C99)
      (C99)
      Nearest integer floating-point
      (C99)(C99)(C99)
      (C23)(C23)(C23)(C23)
      Floating-point manipulation
      (C99)(C99)
      (C99)(C23)
      (C99)
      Narrowing operations
      (C23)
      (C23)
      (C23)
      (C23)
      (C23)
      (C23)
      Quantum and quantum exponent
      Decimal re-encoding functions
      Total order and payload functions
      Classification
      Error and gamma functions
      (C99)
      (C99)
      (C99)
      (C99)
      Types
      Macro constants
      Special floating-point values
      (C99)(C23)
      Arguments and return values
      Error handling
      Fast operation indicators
       
      Defined in header<math.h>
      float       cbrtf(float arg);
      (1)(since C99)
      double      cbrt(double arg);
      (2)(since C99)
      longdouble cbrtl(longdouble arg);
      (3)(since C99)
      Defined in header<tgmath.h>
      #define cbrt( arg )
      (4)(since C99)
      1-3) Computes the cube root ofarg.
      4) Type-generic macro: Ifarg has typelongdouble,cbrtl is called. Otherwise, ifarg has integer type or the typedouble,cbrt is called. Otherwise,cbrtf is called.

      Contents

      [edit]Parameters

      arg - floating-point value

      [edit]Return value

      If no errors occur, the cube root ofarg (\(\small{\sqrt[3]{arg} }\)3arg), 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 inmath_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 topow(arg,1.0/3) because the rational number\(\small{\frac1{3} }\)
      1
      3
      is typically not equal to1.0/3 andstd::pow cannot raise a negative base to a fractional exponent. Moreover,cbrt(arg) usually gives more accurate results thanpow(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.000000cbrt(-0.125)   = -0.500000Special values:cbrt(-0)       = -0.000000cbrt(+inf)     = infAccuracy:cbrt(343)      = 7.00000000000000000pow(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

      (C99)(C99)
      computes a number raised to the given power (\(\small{x^y}\)xy)
      (function)[edit]
      (C99)(C99)
      computes square root (\(\small{\sqrt{x} }\)x)
      (function)[edit]
      (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]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/numeric/math/cbrt&oldid=172001"

      [8]ページ先頭

      ©2009-2025 Movatter.jp