+ 1
Why float cannot be applied on modulus operator?
9 Réponses
+ 2
because if you for example divide 2.5 by 2 you get 1.25 and not 1, so there is no left over part and it doesn‘t really make sense to define % in that context
+ 2
Because C was designed to provide an efficient high-level programming environment to the PDP-11 and it didn't have a modulus instruction for floating point numbers.
+ 1
@Max module for float has sense... In your example 2.5 % 2 is 0.5.. Much languages make work they module operator working with float numbers
Anyway you cannot use floats with % operator because, standard tell that you cannot... Simple... But not all is losed... Exist a function for this, fmod and work like you expect
0
KrOW the only ideals in a field are the 0 ideal and the field itself, so your arbitrary definition had no justification
0
Max Its better make difference between module math (allowed in interger field only) and module computing (where float are allowed also)... We here saying of module computing
0
plz explain in a more simple way
0
You don't need it for floats, because they can represent a number with decimals
integer cant do that, they just cut of the part. This part, which is cut off (rest), can be obtained by the modulus operator
example:
For floats or doubles:
3/2 = 1.5 (exact result, no rest)
13/5 = 2.6 (exact)
For integer:
3/2 = 1 (rest 1, because 2*1 + 1 =3)
13/5 = 2 (rest 3, because 5*2 + 3 = 13)
remember how you started learning to divide in primary school
0
Matthias thnx