The cbrt() function in D returns the cube root of a number.
Here is the mathematical representation of the cbrt() function:
Note:
import std.mathis required to use this function.
cbrt(number)
cbrt() requires a number as a parameter.
- If
-0.0,real.infinity,-real.infinity,real.nan, or-real.nanis sent as a parameter, the function returns the parameter as it is.
cbrt() returns the cube root of the number sent as a parameter.
The following example shows how to use cbrt() in D.
import core.stdc.stdio;import std.stdio;//The header required for the functionimport std.math;int main(){//Perfect cube rootwriteln ("The value of cbrt(8.0) : ",cbrt(8.0));writeln ("The value of cbrt(0.0) : ",cbrt(0.0));//Non-perfect cube rootwriteln ("The value of cbrt(4.4) : ",cbrt(4.4));writeln ("The value of cbrt(25.0) : ",cbrt(25.0));writeln ("The value of cbrt(-4.5) : ",cbrt(-4.5));//Exceptional outputswriteln ("The value of cbrt(-0.0) : ",cbrt(-0.0));writeln ("The value of cbrt(real.infinity) : ",cbrt(real.infinity));writeln ("The value of cbrt(-real.infinity) : ",cbrt(-real.infinity));writeln ("The value of cbrt(real.nan) : ",cbrt(real.nan));writeln ("The value of cbrt(-real.nan) : ",cbrt(-real.nan));return 0;}
Note: The code explanation is commented along with the code.