How does modulation work with the float data type?

I am trying to figure out a simple module operation by the data type of float.

float a=3.14f;
float b=10f;
result=a%b;

I get the result = 3.14

Another example of using decimal data types:

decimal p=10;
decimal q=40;
result=p%q;

receiving a response = 20.

I don’t understand how the module works?

+4
source share
2 answers

From the C # language specification in the remainder of the floating point. In case x % yif xand y- positive finite values.

zis the result x % yand is calculated as x – n * y, where nis the largest possible integer that is less than or equal to x / y.

# , , , NaN, 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
+8

msdn , :

http://msdn.microsoft.com/en-us/library/0w4e0fzs.aspx

int result = x % y;, , x % y, . , Console.WriteLine(5.0 % 2.2);, .6. , , 2,2 5.0 . , 5 - 2.2 (2), .6

+3

All Articles