Jump to content
Sign in to follow this  
Czar

maths bug

Recommended Posts

I found this problem

 

w3label1.Caption := inttostr(150*(5 mod 10)); // should be 750 but it results in 0

w3label2.Caption := inttostr((5 mod 10)*150); // results in 750

 

They should both result in 750. However, the first one results in 0. I have let Jon know but he didn't think much could be done about it. I thought I would at least post it as a bug so people are aware of it.

Share this post


Link to post
Share on other sites

 

IntToStr(150*5 mod 10);  // (150*5%10).toString() = 0 ????
IntToStr(5 mod 10*150); // (5%10*150).toString() = 750 OK
// ---> workaround <---
150*variant(5 mod 10); // (150*(5%10)) = 750 OK
Variant(5 mod 10)*150; // ((5%10)*150) = 750 OK

Share this post


Link to post
Share on other sites

It is the lack of being able to trust BEDMAS rules which is annoying. I can deal with the work-around but it took me about 30 minutes to figure out it was the equation resulting in 0 that was at fault when I was trying to figure out why the game wasn't working correctly. It should work out that (5 mod 10) first.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×