如何模操作的工作方式与浮点数据类型?浮点、数据类型、操作、方式

2023-09-03 04:01:25 作者:怎么敷衍怎

我米试图找出对浮点数据类型的简单模操作。

 浮起= 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 of x % y and is computed as x – n * y, where n is the largest possible integer that is less than or equal to x / 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