Page 1 of 1

[PB 6.00] ASM vs. C: different floating point results

Posted: Thu May 26, 2022 9:23 pm
by Little John
Hi,

I have written several PureBasic procedures that do statistical calculations. Some of them give different results depending on whether they are compiled with the ASM backend or with the C backend. After several tests I found out that there are differences already for basic floating point calculations.

Here is just one simple example:

Code: Select all

; PureBasic 6.0 Beta 8 (x64) on Windows

x.d = 1.9379 * 0.7295
Debug x    ; 1.4136980499999998
Debug #PI  ; 3.1415926535897931

x / #PI
Debug x    ; ASM backend: 0.44999406539374676
           ;   C backend: 0.44999401577479958

Re: [PB 6.00] ASM vs. C: different floating point results

Posted: Thu May 26, 2022 10:01 pm
by skywalk
Yeah, this is a big problem for me.
ASM matches the MS Calculator.
C+opt is almost like stuck at FLOAT instead of DOUBLE? :(

Re: [PB 6.00] ASM vs. C: different floating point results

Posted: Thu May 26, 2022 11:53 pm
by jack
the problem is with the constant #PI, if you change it to PI.d=3.1415926535897932 then it's ok

Re: [PB 6.00] ASM vs. C: different floating point results

Posted: Fri May 27, 2022 3:14 pm
by Little John
jack wrote:the problem is with the constant #PI, if you change it to PI.d=3.1415926535897932 then it's ok
This actually fixed all the compatibility issues in my private statistics library.
Thanks a lot!

Re: [PB 6.00] ASM vs. C: different floating point results

Posted: Fri May 27, 2022 4:17 pm
by infratec
A short test:

Code: Select all

Debug #PI

#Test1 = 3.1415926535897932384
Debug #Test1

#Test2 = 3.1415926535897932
Debug #Test2
Debug StrD(#Test2, 20)

Define f.f
Define d.d

f = #Test1
d = #Test1

Debug f
Debug StrD(d, 20)
Results in:

Code: Select all

3.1415926535897931
3.1415926535897931
3.1415926535897931
3.14159265358979310000
3.14159274101257
3.14159265358979310000
PB 5.73 x86 on WIn x64

Very strange.

Re: [PB 6.00] ASM vs. C: different floating point results

Posted: Fri May 27, 2022 5:25 pm
by STARGÅTE
It is not the #PI constant itself, who makes problems.
It is the short form of the operation x = x * y --> x* y

Code: Select all

Debug #PI

d1.d = #PI
Debug d1

d2.d = 1.0 * #PI
Debug d2

d3.d = 1.0
d3 * #PI
Debug d3
This is not the first one of this kind of bugs in the C-backend and it is challenging to find all these bugs, because they are not obviously.

Re: [PB 6.00] ASM vs. C: different floating point results

Posted: Fri May 27, 2022 6:21 pm
by Little John
STARGÅTE wrote: Fri May 27, 2022 5:25 pm It is not the #PI constant itself, who makes problems.
It is the short form of the operation x = x * y --> x* y
Hi,

using the long form of the operation might fix the issue in some cases, but unfortunately is not a general workaround, see https://www.purebasic.fr/english/viewto ... 98#p584898