C - finding cube root of a negative number with pow function

后端 未结 4 388
没有蜡笔的小新
没有蜡笔的小新 2021-01-17 12:13

In real world cube root for a negative number should exist: cuberoot(-1)=-1, that means (-1)*(-1)*(-1)=-1 or cuberoot(-27)=-3, that me

4条回答
  •  别那么骄傲
    2021-01-17 12:41

    7.12.7.1 The cbrt functions

    Synopsis

    #include 
    double cbrt(double x);
    float cbrtf(float x);
    long double cbrtl(long double x);
    

    Description

    The cbrt functions compute the real cube root of x.


    If you're curious, pow can't be used to compute cube roots because one-third is not expressible as a floating-point number. You're actually asking pow to raise -27.0 to a rational power very nearly equal to 1/3; there is no real result that would be appropriate.

提交回复
热议问题