Dear Vasilis,
The result of the fifth multiplications is greater than INT_MAX. For 32-bits integers this is approximately 2E9. Apparently Ox does not check for integer overflow, and the result of the computation is the true result minus 2^32.
To avoid the problem you could use doubles instead of integers ( decl variable5 = 4769856.0 * 600.0 ; ), but then the result is not exact.
Regards,
Jaap
> -----Original Message-----
> From: The ox-users list is aimed at all Ox users
> [mailto:[log in to unmask]]On Behalf Of V. Sarafidis
> Sent: Thursday, 04 August, 2005 12:49
> To: [log in to unmask]
> Subject: puzzle
>
>
> Hello,
>
> I have a short but puzzling question:
>
> I am running the following elementary code in Ox
>
> #include <oxstd.h>
>
> main()
> {
> decl variable1 = 856*600;
> decl variable2 = 9856*600;
> decl variable3 = 69856*600;
> decl variable4 = 769856*600;
> decl variable5 = 4769856*600;
>
> print("\n variable1 = ", variable1);
> print("\n variable2 = ", variable2);
> print("\n variable3 = ", variable3);
> print("\n variable4 = ", variable4);
> print("\n variable5 = ", variable5);
> }
>
> The results I get are
>
> variable1 = 513600
> variable2 = 5913600
> variable3 = 41913600
> variable4 = 461913600
> variable5 = -1433053696
>
> So the fifth product is not only incorrect in value but it
> has also the
> wrong sign! I must be doing something wrong but I cannot
> figure out what. I
> would appreciate any help you could provide.
>
> Vasilis
>
|