如何模操作的工作方式与浮点数据类型? [英] How does modulus operation works with float data type?
问题描述
我米试图找出对浮点数据类型的简单模操作。
浮起= 3.14f;
浮动B = 10F;
结果= x%A;
我米得到的结果= 3.14
使用十进制数据类型又如:
十进制P = 10;
十进制Q = 40;
结果= P%Q;
得到的答案= 20。
我不理解它是如何工作的弹性模量?
从浮点其余的C#语言规范。在 X%Y
如果 X
和是
的情况下,是正有限值。
以Z
是X%Y
的结果,并计算为X - N * Y
,其中N
是国内最大的可能整数小于或等于X / Y
。
C#语言规范还明确列出了该怎么做了非零有限值,零,无穷的所有可能组合的情况下,表和NaN的可能出现浮动X%Y的点值。
y值 | + Y -y +0 -0 +∞-∞NaN的 ----- + ---------------------------- X + X | + Z + Z楠楠X X为NaN -x | -z -z楠楠-x -x为NaN v + 0 | + 0 + 0楠楠+ 0 + 0的NaN 1-0 | -0 -0楠楠-0 -0的NaN L +∞|楠楠楠楠楠楠的NaN ü-∞|楠楠楠楠楠楠的NaN Ë为NaN |楠楠楠楠楠楠的NaN
I m trying to find out a simple modulus operation on float data type.
float a=3.14f;
float b=10f;
result=a%b;
I m getting result= 3.14
Another example using decimal data types:
decimal p=10;
decimal q=40;
result=p%q;
getting answer=20.
I am not understanding how does modulus works?
From the C# language spec on floating point remainder. In the case of x % y
if x
and y
are positive finite values.
z
is the result ofx % y
and is computed asx – n * y
, wheren
is the largest possible integer that is less than or equal tox / y
.
The C# language spec also clearly outlines the table of what to do with the cases of all possible combinations of nonzero finite values, zeros, infinities, and NaN’s which can occur with floating point values of x % y.
y value | +y –y +0 –0 +∞ –∞ NaN -----+---------------------------- x +x | +z +z NaN NaN x x NaN –x | –z –z NaN NaN –x –x NaN v +0 | +0 +0 NaN NaN +0 +0 NaN a –0 | –0 –0 NaN NaN –0 –0 NaN l +∞ | NaN NaN NaN NaN NaN NaN NaN u –∞ | NaN NaN NaN NaN NaN NaN NaN e NaN | NaN NaN NaN NaN NaN NaN NaN
这篇关于如何模操作的工作方式与浮点数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!