Author Topic: Calculation error.  (Read 3316 times)

0 Members and 1 Guest are viewing this topic.

Offline Ryster

  • Newbie
  • Posts: 77
    • View Profile
Calculation error.
« on: February 26, 2021, 02:00:30 pm »
Hello.
I have such a problem. Well, the output of code running on 32-bit is different from that of code running on 64-bit. At the same time, it calculates incorrectly in the 64-bit version, and correctly in the 32-bit version. Is there any advice for this, or does it have to be.
Regards - Ryster

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Calculation error.
« Reply #1 on: February 26, 2021, 02:07:44 pm »
Hello.
I have such a problem. Well, the output of code running on 32-bit is different from that of code running on 64-bit. At the same time, it calculates incorrectly in the 64-bit version, and correctly in the 32-bit version. Is there any advice for this, or does it have to be.
Regards - Ryster

Say what the problem is, maybe it's been reported and there is a fix, maybe it needs to be fixed, maybe it's unfixable in near future.

So my advice is to please provide more details.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Calculation error.
« Reply #2 on: February 26, 2021, 02:16:44 pm »
Please paste the code you are using so we can help debug
Shuwatch!

Offline Ryster

  • Newbie
  • Posts: 77
    • View Profile
Re: Calculation error.
« Reply #3 on: February 26, 2021, 02:18:55 pm »
Perhaps this problem has already been raised. As I wrote. With the same input data, the result is different. Except that the 32-bit version counts correctly. I suspect a different rounding procedure inside the 64 bit compiler.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Calculation error.
« Reply #4 on: February 26, 2021, 02:19:39 pm »
We can't help you if you don't give us more info.
Shuwatch!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Calculation error.
« Reply #5 on: February 26, 2021, 02:26:48 pm »
My guess is it’s the difference in the floating point math used. 

Look at the code here, and see if it “corrects” the issue for you: https://qb64.freeforums.net/thread/134/change-floating-point-precision

https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Ryster

  • Newbie
  • Posts: 77
    • View Profile
Re: Calculation error.
« Reply #6 on: February 26, 2021, 02:32:30 pm »
Thanks to SMcNeill, it is just like you wrote.
Regards - Ryster

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Calculation error.
« Reply #7 on: February 26, 2021, 02:34:57 pm »
It’s the difference in 80-bit FPU math processing (32-bit machines) vs 64-bit SSE math processing (64-bit machines).  The code I provided should allow you to set what you need to get the results you’re looking for. 
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Ryster

  • Newbie
  • Posts: 77
    • View Profile
Re: Calculation error.
« Reply #8 on: February 26, 2021, 02:46:10 pm »
In my free time I will test and inform.

Regards - Ryster

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Calculation error.
« Reply #9 on: February 26, 2021, 03:50:43 pm »
Another stunning endorsement for string math!

Yep, it's going to be what Steve said. When we get to 128 bit encryption, it will probably be this problem all over again. That's why I like string math, with the exception it's bit of work to program.

Similar to this topic, I wonder what Ed's app he posted would do under this 32-bit 64-bit floating point difference?

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Ryster

  • Newbie
  • Posts: 77
    • View Profile
Re: Calculation error.
« Reply #10 on: February 26, 2021, 05:38:06 pm »
Double precision successfully solved the problem. The calculation is now valid on the 64-bit version. This error appeared sporadically, therefore it was difficult to notice it. It only occurred with certain numerical values. For example, the calculations for 1990 are correct and 2021 are incorrect. Thanks for your willingness to help.
Regards - Ryster