Namespaces
Variants

cbrt, cbrtf, cbrtl

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

Trigonometric and hyperbolic functions
Nearest integer floating-point
(C99) (C99) (C99)
(C23) (C23) (C23) (C23)
Floating-point manipulation
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
Arguments and return values
Error handling
Fast operation indicators
Definiert im Header <math.h>
float cbrtf ( float arg ) ;
(1) (seit C99)
double cbrt ( double arg ) ;
(2) (seit C99)
long double cbrtl ( long double arg ) ;
(3) (seit C99)
Definiert im Header <tgmath.h>
#define cbrt( arg )
(4) (seit C99)
1-3) Berechnet die Kubikwurzel von arg .
4) Typgenerisches Makro: Wenn arg den Typ long double hat, wird cbrtl aufgerufen. Andernfalls, wenn arg ganzzahligen Typ oder den Typ double hat, wird cbrt aufgerufen. Andernfalls wird cbrtf aufgerufen.

Inhaltsverzeichnis

Parameter

arg - Gleitkommawert

Rückgabewert

Wenn keine Fehler auftreten, wird die Kubikwurzel von arg ( 3 arg ) zurückgegeben.

Wenn ein Bereichsfehler aufgrund von Unterlauf auftritt, wird das korrekte Ergebnis (nach Rundung) zurückgegeben.

Fehlerbehandlung

Fehler werden gemeldet, wie in math_errhandling spezifiziert.

Wenn die Implementierung IEEE-Gleitkommaarithmetik (IEC 60559) unterstützt,

  • wenn das Argument ±0 oder ±∞ ist, wird es unverändert zurückgegeben
  • wenn das Argument NaN ist, wird NaN zurückgegeben.

Hinweise

cbrt ( arg ) is not equivalent to pow ( arg, 1.0 / 3 ) because the rational number
1
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).

Beispiel

#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));
}

Mögliche Ausgabe:

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

Referenzen

  • C23-Standard (ISO/IEC 9899:2024):
  • 7.12.7.1 Die cbrt-Funktionen (S.: TBD)
  • 7.25 Typgenerische Mathematik <tgmath.h> (S.: TBD)
  • F.10.4.1 Die cbrt-Funktionen (S.: TBD)
  • C17-Standard (ISO/IEC 9899:2018):
  • 7.12.7.1 Die cbrt-Funktionen (S: 180-181)
  • 7.25 Typgenerische Mathematik <tgmath.h> (S: 272-273)
  • F.10.4.1 Die cbrt-Funktionen (S: 381-)
  • C11-Standard (ISO/IEC 9899:2011):
  • 7.12.7.1 Die cbrt-Funktionen (S. 247)
  • 7.25 Typgenerische Mathematik <tgmath.h> (S. 373-375)
  • F.10.4.1 Die cbrt-Funktionen (S. 524)
  • C99-Standard (ISO/IEC 9899:1999):
  • 7.12.7.1 Die cbrt-Funktionen (S. 228)
  • 7.22 Typgenerische Mathematik <tgmath.h> (S. 335-337)
  • F.9.4.1 Die cbrt-Funktionen (S. 460)

Siehe auch

(C99) (C99)
berechnet eine Zahl potenziert mit dem gegebenen Exponenten ( x y )
(Funktion)
(C99) (C99)
berechnet Quadratwurzel ( x )
(Funktion)
(C99) (C99) (C99)
berechnet Quadratwurzel der Summe der Quadrate zweier gegebener Zahlen ( x 2
+y 2
)
(Funktion)