MOD function does not work! So be warned!

Michael D Mays michael at GreppyDreppies.com
Wed Apr 3 19:55:01 EST 2002


Rob Cozens of rcozens at pon.net wrote the following on 4/3/02 9:59 AM

>> on testMod
>>  put 249 into var1
>>  put var1 into var2
>>  add 1.0 to var1
>>  repeat 10
>>   add 0.1 to var2
>>  end repeat
>>  put (var1=var2)&&((var1 mod 5)=(var2 mod 5))
>> end testMod

On the Mac with PPC numerics as I understand it 249 and 1 are represented
exactly as is the sum of 249+1.
 249   -> 011111001
+  1   -> 000000001
=250   -> 011111010 -> var1

 249   -> 011111001
+  0.1 -> 000000000.00011001100110011001100110011 ...
+  0.1 -> 000000000.00011001100110011001100110011 ...
+  0.1 -> 000000000.00011001100110011001100110011 ...
+  0.1 -> 000000000.00011001100110011001100110011 ...
+  0.1 -> 000000000.00011001100110011001100110011 ...
+  0.1 -> 000000000.00011001100110011001100110011 ...
+  0.1 -> 000000000.00011001100110011001100110011 ...
+  0.1 -> 000000000.00011001100110011001100110011 ...
+  0.1 -> 000000000.00011001100110011001100110011 ...
+  0.1 -> 000000000.00011001100110011001100110011 ...
=249.9*-> 011111001.11111111111111111111111111110 ... -> var2
*249.999999...
var1<>var2

add this line to the beginning of the above script
 set the numberFormat to "0.########################################"
and append this to the penultimate line.
 &&var1&&var2 
Now the result is
 true false 250 249.99999999999994315658113919199

MOD returns the remainder left when one number divides into another. So we
are asking for
011111001.00011001100110011001100110011 ... / 00000101 -> a remainder
vs
011111010 / 00000101 -> no remainder

= on some systems wants an exact match. Not so using PPC numerics. They only
need to round to within 15 decimal digits or so (There two decimal orders of
rounding for Dar:). Which the above two numbers do. If you would have ran
the loop to 1000 and adjusted your parameters for 100 instead of 1 you would
have found
 false false

MOD is working. = is working. MOD is strictly a binary comparison. = does
rounding trying to conform to our decimal perception of the universe.:)

michael




More information about the use-livecode mailing list