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

Everything else that doesn't fall into one of the other PB categories.
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

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

Post 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
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

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

Post 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? :(
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
jack
Addict
Addict
Posts: 1336
Joined: Fri Apr 25, 2003 11:10 pm

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

Post by jack »

the problem is with the constant #PI, if you change it to PI.d=3.1415926535897932 then it's ok
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

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

Post 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!
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

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

Post 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.
User avatar
STARGÅTE
Addict
Addict
Posts: 2067
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

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

Post 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.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

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

Post 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
Post Reply