加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Vb.net和C的MATH函数中任何已知的歧义

发布时间:2020-12-17 07:17:14 所属栏目:百科 来源:网络整理
导读:最近我发现C fmod函数的结果和它在Vb.net中的等效Math.IEEERemainder存在模糊性 如果我们在C中计算fmod(4.1887902053333335 / 6.283185307,1.0),我们得到, 0.6666666677277而Vb.net中的Math.IEEERemainder(4.1887902053333335 / 6.283185307,1.0)导致-0.3333
最近我发现C fmod函数的结果和它在Vb.net中的等效Math.IEEERemainder存在模糊性

如果我们在C中计算fmod(4.1887902053333335 / 6.283185307,1.0),我们得到,
0.6666666677277而Vb.net中的Math.IEEERemainder(4.1887902053333335 / 6.283185307,1.0)导致-0.33333333322723因此我们发现结果完全不同会严??重影响输出.

我目前正在开发一个项目,它有几个数学运算,包括正弦,双曲余弦,模数等,最初是在C中,我的任务是在Vb.net中转换它.

虽然大多数代码可以简单地在网络上进出在线转换器,但这些数学模糊性仍然隐藏着损害结果.

有没有人知道这种已知的差异,特别是对于C的Vb.net中的Math类?

解决方法

doc on Math.IEEERemainder说如下:

The IEEERemainder method is not the same as the modulus operator. Although both return the remainder after division,the formulas they use are different. The formula for the IEEERemainder method is:

IEEERemainder = dividend – (divisor * Math.Round(dividend / divisor))

In contrast,the formula for the modulus operator is:

Modulus = (Math.Abs(dividend) – (Math.Abs(divisor) *
(Math.Floor(Math.Abs(dividend) / Math.Abs(divisor))))) *
Math.Sign(dividend)

所以,它只是一个不同的功能.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读