本文介绍了是Math.IEEERemainder(X,Y)等价于x%Y?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有之间的差异 Math.IEEERemainder(X,Y) X%是

推荐答案

没有,他们是不等价的。 MSDN 显示了用于模和IEEERemainder不同的公式和具有短样本节目表现出的差异:

No, they are not equivalent. MSDN shows the different formulas used for modulo and for IEEERemainder and has a short sample program exhibiting the differences:

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

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

,他们有不同的/相同的输出(从MSDN采取)的一些例子:

Some examples where they have different/identical output (taken from MSDN):

                         IEEERemainder              Modulus
   3 / 2 =                          -1                    1
   4 / 2 =                           0                    0
   10 / 3 =                          1                    1
   11 / 3 =                         -1                    2
   27 / 4 =                         -1                    3
   28 / 5 =                         -2                    3
   17.8 / 4 =                      1.8                  1.8
   17.8 / 4.1 =                    1.4                  1.4
   -16.3 / 4.1 =    0.0999999999999979                   -4
   17.8 / -4.1 =                   1.4                  1.4
   -17.8 / -4.1 =                 -1.4                 -1.4

又见这个好answer通过类似的问题sixlettervariables。

See also this good answer by sixlettervariables on a similar question.

这篇关于是Math.IEEERemainder(X,Y)等价于x%Y?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-29 03:44