罪(M_PI) [英] sin (M_PI)

查看:91
本文介绍了罪(M_PI)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我使用以下代码:

printf("%g",sin(M_PI))

和得到1.22461e-16而不是零。

有没有人知道为什么,我能做些什么呢?


谢谢,

Adam

Hi,
I am using the following code:
printf("%g", sin(M_PI))
and getting 1.22461e-16 instead of zero.
Does anyone have any idea why, and what I can do about it?

Thanks,
Adam

推荐答案

7月12日,11:14,Adam< a ... @ sendnospam.comwrote:
On 12 Jul, 11:14, Adam <a...@sendnospam.comwrote:



我使用以下代码:

printf("%g",sin(M_PI))

并且得到1.22461e-16而不是零。

有没有人知道为什么,
Hi,
I am using the following code:
printf("%g", sin(M_PI))
and getting 1.22461e-16 instead of zero.
Does anyone have any idea why,



浮点精度的常见问题,我想。

The usual issues with floating point accuracy, I''d think.


我能做些什么呢?
and what I can do about it?



查看你的目标实现是否有另一个sin()

实现(sinl(),它接受并返回long double,可能是

可用,以及PI的合适定义。

See if your target implementation has an alternative sin()
implementation (sinl(), which takes and returns long double, may be
available for example) and a suitable definition of PI.


7月12日,11:26,mark_blue ... @ pobox.com写道:
On 12 Jul, 11:26, mark_blue...@pobox.com wrote:

7月12日,11:14,Adam< a ... @ sendnospam.comwrote:
On 12 Jul, 11:14, Adam <a...@sendnospam.comwrote:



我使用以下代码:

printf("%g",sin(M_PI))

并得到1.22461e-16而不是零。

有没有人知道为什么,
Hi,
I am using the following code:
printf("%g", sin(M_PI))
and getting 1.22461e-16 instead of zero.
Does anyone have any idea why,



漂浮的常见问题点精度,我想。


The usual issues with floating point accuracy, I''d think.


我能做些什么呢?
and what I can do about it?



查看你的目标实现是否有另一个罪()

实现(sinl(),它接受并返回long double,可能是

例如可用)和PI的合适定义。


See if your target implementation has an alternative sin()
implementation (sinl(), which takes and returns long double, may be
available for example) and a suitable definition of PI.



我必须放弃回复自己...


sinl()是标准的一部分,应该可用。找到一个好的

定义PI可能会更困难,但GNU libc标题给出: -


#define M_PIl 3.1415926535897932384626433832795029L / *

pi * /

I must give up replying to myself...

sinl() is part of the standard and should be available. Finding a good
definition of PI may be more difficult, but a GNU libc header gives:-

# define M_PIl 3.1415926535897932384626433832795029L /*
pi */


Adam写道:
Adam wrote:



我使用以下代码:

printf("%g",sin(M_PI))

并获得1.22461e-16而不是零。

有没有人知道为什么,我能做些什么呢?
Hi,
I am using the following code:
printf("%g", sin(M_PI))
and getting 1.22461e-16 instead of zero.
Does anyone have any idea why, and what I can do about it?



首先,M_PI未在标准C中定义,但大多数实现

将其定义为扩展名。你也可以在运行时计算它的价值

或自己定义。


其次要确保你为printf包含stdio.h和math.h和罪。

并尝试使用%f格式说明符。

Firstly M_PI is not defined in Standard C, though most implementations
define it as an extension. You can also compute it''s value at runtime
or define it yourself.

Secondly make sure you include stdio.h and math.h for printf and sin.
And try using the %f format specifier.


这篇关于罪(M_PI)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆