Ç - 寻找具有战俘功能负数的立方根 [英] C - finding cube root of a negative number with pow function
问题描述
在现实世界中立方根为负数应该存在: cuberoot(-1)= - 1
,这意味着( - 1)*( - 1)*( - 1)= - 1
要么 cuberoot(-27)= - 3
,这意味着( - 3)*( - 3)*( - 3)= - 27
但是,当我使用 POW
函数计算负数的立方根在C,我得到男
(不一个数字)
双cuber;
cuber = POW(( - 27),(1./3));
的printf(cuber =%F \\ N,cuber);
输出: cuber =楠
有没有什么方法来计算在C负数的立方根?</ P>
7.12.7.1的 CBRT
功能
简介
的#include&LT;&math.h中GT;
双CBRT(双X);
浮cbrtf(浮X);
长双cbrtl(长双X);
说明
的 CBRT
函数计算 X
。
如果你好奇, POW
不能用于计算立方根,因为有三分之一是不是前pressible作为一个浮点数。你实际上问 POW
来筹集 -27.0
理性力量非常接近等于1/3;没有真正的结果,这将是适当的。
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 means (-3)*(-3)*(-3)=-27
But when I calculate cube root of a negative number in C using pow
function, I get nan
(not a number)
double cuber;
cuber=pow((-27.),(1./3.));
printf("cuber=%f\n",cuber);
output: cuber=nan
Is there any way to calculate cube root of a negative number in C?
7.12.7.1 The cbrt
functions
Synopsis
#include <math.h>
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.
这篇关于Ç - 寻找具有战俘功能负数的立方根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!