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
Definido en el encabezado <math.h>
float cbrtf ( float arg ) ;
(1) (desde C99)
double cbrt ( double arg ) ;
(2) (desde C99)
long double cbrtl ( long double arg ) ;
(3) (desde C99)
Definido en el encabezado <tgmath.h>
#define cbrt( arg )
(4) (desde C99)
1-3) Calcula la raíz cúbica de arg .
4) Macro genérico de tipos: Si arg tiene tipo long double , cbrtl es llamado. De lo contrario, si arg tiene tipo entero o el tipo double , cbrt es llamado. De lo contrario, cbrtf es llamado.

Contenidos

Parámetros

arg - valor de punto flotante

Valor de retorno

Si no ocurren errores, se devuelve la raíz cúbica de arg ( 3 arg ).

Si ocurre un error de rango debido a desbordamiento inferior, se devuelve el resultado correcto (después del redondeo).

Manejo de errores

Los errores se reportan como se especifica en math_errhandling .

Si la implementación soporta aritmética de punto flotante IEEE (IEC 60559),

  • si el argumento es ±0 o ±∞, se devuelve sin cambios
  • si el argumento es NaN, se devuelve NaN.

Notas

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).

Ejemplo

#include <float.h>
#include <math.h>
#include <stdio.h>
int main(void)
{
    printf("Uso normal:\n"
           "cbrt(729)      = %f\n", cbrt(729));
    printf("cbrt(-0.125)   = %f\n", cbrt(-0.125));
    printf("Valores especiales:\n"
           "cbrt(-0)       = %f\n", cbrt(-0.0));
    printf("cbrt(+inf)     = %f\n", cbrt(INFINITY));
    printf("Precisión:\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));
}

Salida posible:

Uso normal:
cbrt(729)      = 9.000000
cbrt(-0.125)   = -0.500000
Valores especiales:
cbrt(-0)       = -0.000000
cbrt(+inf)     = inf
Precisión:
cbrt(343)      = 7.00000000000000000
pow(343,1.0/3) = 6.99999999999999911

Referencias

  • Estándar C23 (ISO/IEC 9899:2024):
  • 7.12.7.1 Las funciones cbrt (p: TBD)
  • 7.25 Matemáticas genéricas de tipos <tgmath.h> (p: TBD)
  • F.10.4.1 Las funciones cbrt (p: TBD)
  • Estándar C17 (ISO/IEC 9899:2018):
  • 7.12.7.1 Las funciones cbrt (p: 180-181)
  • 7.25 Matemáticas genéricas de tipo <tgmath.h> (p: 272-273)
  • F.10.4.1 Las funciones cbrt (p: 381-)
  • Estándar C11 (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)
  • Estándar C99 (ISO/IEC 9899:1999):
  • 7.12.7.1 Las funciones cbrt (p: 228)
  • 7.22 Matemáticas genéricas de tipo <tgmath.h> (p: 335-337)
  • F.9.4.1 Las funciones cbrt (p: 460)

Véase también

(C99) (C99)
calcula un número elevado a la potencia dada ( x y )
(función)
(C99) (C99)
calcula la raíz cuadrada ( x )
(función)
(C99) (C99) (C99)
calcula la raíz cuadrada de la suma de los cuadrados de dos números dados ( x 2
+y 2
)
(función)