Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

communitycreator
d

What is cbrt() in D?

harris910

The cbrt() function in D returns the cube root of a number.

Here is the mathematical representation of the cbrt() function:

x3=cbrt(X)\sqrt[3]{x}=cbrt(X)

Note: import std.math is required to use this function.

Syntax

cbrt(number)

Parameter

cbrt() requires a number as a parameter.

  • If -0.0, real.infinity, -real.infinity, real.nan, or -real.nan is sent as a parameter, the function returns the parameter as it is.

Return value

cbrt() returns the cube root of the number sent as a parameter.

Code

The following example shows how to use cbrt() in D.

import core.stdc.stdio;
import std.stdio;
//The header required for the function
import std.math;

int main()
{
    //Perfect cube root
    writeln ("The value of cbrt(8.0) : ",cbrt(8.0));

    writeln ("The value of cbrt(0.0) : ",cbrt(0.0));


    //Non-perfect cube root
    writeln ("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 outputs
    writeln ("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;
}
Using the cbrt() function

Note: The code explanation is commented along with the code.

RELATED TAGS

communitycreator
d
RELATED COURSES

View all Courses

Keep Exploring