Jump to content


Photo

maths bug


  • Please log in to reply
3 replies to this topic

#1 Czar

Czar
  • Members
  • 131 posts

Posted 11 August 2017 - 10:38 PM

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.

#2 Laksekjønn

Laksekjønn
  • Members
  • 428 posts

Posted 11 August 2017 - 11:14 PM

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


#3 Czar

Czar
  • Members
  • 131 posts

Posted 11 August 2017 - 11:59 PM

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.

#4 jarto

jarto
  • Administrators
  • 7 posts
  • LocationVaasa, Finland
  • Enterprise Edition

Posted 12 August 2017 - 11:43 AM

Thank you for reporting the bug. We can reproduce it in the latest released version, but not in the development version.
  • Jørn E. Angeltveit and Czar like this




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users