QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: STxAxTIC on February 10, 2021, 02:50:59 pm

Title: Alright, this is weird on my machine...
Post by: STxAxTIC 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.  
Title: Re: Alright, this is weird on my machine...
Post by: bplus 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.  
Title: Re: Alright, this is weird on my machine...
Post by: STxAxTIC 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:

Title: Re: Alright, this is weird on my machine...
Post by: SMcNeill 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.
Title: Re: Alright, this is weird on my machine...
Post by: STxAxTIC 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.
Title: Re: Alright, this is weird on my machine...
Post by: SMcNeill 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.  
Title: Re: Alright, this is weird on my machine...
Post by: SMcNeill 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