Vb.net与C语言中MATH函数的歧义点有哪些?
- 内容介绍
- 文章标签
- 相关推荐
本文共计315个文字,预计阅读时间需要2分钟。
最近我发现C#中使用fmod函数的结果与VB.NET中Math.IEEERemainder存在细微差异,具有模糊性。例如,在C#中计算fmod(4.1887902053333335 / 6.283185307, 1.0),得到0.6666666677277,而在VB.NET中使用Math.IEEERemainder(4.1887902053),结果为0.666666667。
最近我发现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)
所以,它只是一个不同的功能.
本文共计315个文字,预计阅读时间需要2分钟。
最近我发现C#中使用fmod函数的结果与VB.NET中Math.IEEERemainder存在细微差异,具有模糊性。例如,在C#中计算fmod(4.1887902053333335 / 6.283185307, 1.0),得到0.6666666677277,而在VB.NET中使用Math.IEEERemainder(4.1887902053),结果为0.666666667。
最近我发现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)
所以,它只是一个不同的功能.

