GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::cbrt,std::cbrtf,std::cbrtl(3) C++ Standard Libary std::cbrt,std::cbrtf,std::cbrtl(3)

std::cbrt,std::cbrtf,std::cbrtl - std::cbrt,std::cbrtf,std::cbrtl


Defined in header <cmath>
float cbrt ( float arg ); (1) (since C++11)
float cbrtf( float arg );
double cbrt ( double arg ); (2) (since C++11)
long double cbrt ( long double arg ); (3) (since C++11)
long double cbrtl( long double arg );
double cbrt ( IntegralType arg ); (4) (since C++11)


1-3) Computes the cube root of arg.
4) A set of overloads or a function template accepting an argument of any integral
type. Equivalent to 2) (the argument is cast to double).


arg - value of a floating-point or Integral type


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.


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.


std::cbrt(arg) is not equivalent to std::pow(arg, 1.0/3) because the rational number
\(\small{\frac1{3} }\)


1
3


is typically not equal to 1.0/3 and std::pow cannot raise a negative base to a
fractional exponent. Moreover, std::cbrt(arg) usually gives more accurate results
than std::pow(arg, 1.0/3) (see example).

// Run this code


#include <iostream>
#include <iomanip>
#include <cmath>
#include <limits>


int main()
{
std::cout
<< "Normal use:\n"
<< "cbrt(729) = " << std::cbrt(729) << '\n'
<< "cbrt(-0.125) = " << std::cbrt(-0.125) << '\n'
<< "Special values:\n"
<< "cbrt(-0) = " << std::cbrt(-0.0) << '\n'
<< "cbrt(+inf) = " << std::cbrt(INFINITY) << '\n'
<< "Accuracy and comparison with `pow`:\n"
<< std::setprecision(std::numeric_limits<double>::max_digits10)
<< "cbrt(343) = " << std::cbrt(343) << '\n'
<< "pow(343,1.0/3) = " << std::pow(343, 1.0/3) << '\n'
<< "cbrt(-343) = " << std::cbrt(-343) << '\n'
<< "pow(-343,1.0/3) = " << std::pow(-343, 1.0/3) << '\n';
}


Normal use:
cbrt(729) = 9
cbrt(-0.125) = -0.5
Special values:
cbrt(-0) = -0
cbrt(+inf) = inf
Accuracy and comparison with `pow`:
cbrt(343) = 7
pow(343,1.0/3) = 6.9999999999999991
cbrt(-343) = -7
pow(-343,1.0/3) = -nan


pow
powf raises a number to the given power (\(\small{x^y}\)x^y)
powl (function)
(C++11)
(C++11)
sqrt computes square root (\(\small{\sqrt{x} }\)
sqrtf √
sqrtl x)
(C++11) (function)
(C++11)
computes square root of the sum of the squares of two or three (C++17) given
numbers (\(\scriptsize{\sqrt{x^2+y^2} }\)

hypot x2
hypotf +y2
hypotl ), (\(\scriptsize{\sqrt{x^2+y^2+z^2} }\)
(C++11)
(C++11) x2
(C++11) +y2
+z2
)
(function)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.