Author Topic: Alright, this is weird on my machine...  (Read 3689 times)

0 Members and 1 Guest are viewing this topic.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Alright, this is weird on my machine...
« on: February 10, 2021, 02:50:59 pm »
I get two different answers at the bottom of this code. Someone else tells me they get the same answer twice. Can I get some community testing? Or someone otherwise set me straight please.

Code: QB64: [Select]
  1. z = 9223372036854775807 ' This is the biggest allowed number of this type.
  2. '                         (Only here for reference.)
  3.  
  4. a = 2 ^ 55 - 1 '          This number should be odd.
  5. b = 36028797018963967 '   The number above should equal this one.
  6.  
« Last Edit: February 10, 2021, 02:52:51 pm by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Alright, this is weird on my machine...
« Reply #1 on: February 10, 2021, 03:32:23 pm »
It's the ^ that looses precision.
Code: QB64: [Select]
  1. z = 9223372036854775807 ' This is the biggest allowed number of this type.
  2. z = 36028797018963967
  3. '                         (Only here for reference.)
  4. a1 = 1
  5. For p = 1 To 55
  6.     a1 = a1 * 2
  7. a = 2 ^ 55 - 1 '          This number should be odd.
  8. b = 36028797018963967 '   The number above should equal this one.
  9. Print a1 - 1
  10.  
  11.  

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Alright, this is weird on my machine...
« Reply #2 on: February 10, 2021, 04:10:42 pm »
Sure bplus, it's definitely in the power operator, but I'm just gathering some info as to when we see it versus when we don't.

Here are two screenshots from various people (neither are me) whose systems show the two different cases:

« Last Edit: February 10, 2021, 04:12:29 pm by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Alright, this is weird on my machine...
« Reply #3 on: February 10, 2021, 04:36:42 pm »
I’m not at the PC currently, but I’d guess it’s a case of intermediary precision.

A and B might be integer64s, but you haven’t specified your constants.

Try:


a = 2&& ^ 55&& -  1&& ‘     This number should be odd.
b = 36028797018963967&& '   The number above should equal this one.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Alright, this is weird on my machine...
« Reply #4 on: February 10, 2021, 04:39:09 pm »
That fix doesn't do the trick on my computer. I'm curious about both on yours now.
You're not done when it works, you're done when it's right.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Alright, this is weird on my machine...
« Reply #5 on: February 10, 2021, 04:53:45 pm »
Code: QB64: [Select]
  1.     SUB set_dpfpu 'to toggle to double precision floating point math
  2.     SUB set_qbfpu 'to toggle back to what most folks will see with QB64 64-bit default math
  3.  
  4. set_dpfpu
  5.  
  6. z = 9223372036854775807 ' This is the biggest allowed number of this type.
  7. '                         (Only here for reference.)
  8.  
  9. a = (2 ^ 55) - 1 '          This number should be odd.
  10. b = 36028797018963967 '   The number above should equal this one.
  11.  
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Alright, this is weird on my machine...
« Reply #6 on: February 10, 2021, 05:03:22 pm »
Same issue as you see here:

Code: QB64: [Select]
  1.     SUB set_dpfpu 'to toggle to double precision floating point math
  2.     SUB set_qbfpu 'to toggle back to what most folks will see with QB64 64-bit default math
  3.  
  4.  
  5.  
  6.  
  7. 'Let's print our results without screwing with anything first.
  8. x = 5##
  9. y = x / 9##
  10. PRINT USING "QB64 division       #.####################"; y
  11.  
  12.  
  13. 'Set the double precision math
  14. set_dpfpu
  15. x = 5##
  16. y = x / 9##
  17. PRINT USING "QB64 division       #.####################"; y
  18.  
  19. 'Set the QB64 precision math
  20. set_qbfpu
  21. x = 5##
  22. y = x / 9##
  23. PRINT USING "QB64 division       #.####################"; y
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!