using gcc quadmath

General FreeBASIC programming questions.
codelab
Posts: 8
Joined: Mar 31, 2020 11:47

Re: using gcc quadmath

Postby codelab » Apr 06, 2020 22:21

Hi Srvaldez

Absolute fabulous !

I was just doing writing some some overloading functions and had to cast to double when it came to compare.
so this is just great!

Since I switched to version 1.00.0 everything seems reliable.

Regards and thank you for the math, C
srvaldez
Posts: 2327
Joined: Sep 25, 2005 21:54

Re: using gcc quadmath

Postby srvaldez » Apr 07, 2020 0:15

Hi codelab
I updated the include file to include formatted output viewtopic.php?p=270387#p270387
see updated example viewtopic.php?p=270388#p270388
codelab
Posts: 8
Joined: Mar 31, 2020 11:47

Re: using gcc quadmath

Postby codelab » Apr 07, 2020 8:30

Hi Srwaldez

Library very impressive!

All core functionality i have tested so far works ,math is good !
though strtoflt(,) and tostring is still causing headache.

I ran your sample on a win7 machine - 32 bit freebasic, am going to check same on Win10.

Code: Select all

#include "quadmath.bi"

dim as float128 x, y, z

x=7 : Print "x = ";x
y=9 : Print "y = ";y
'if the values are fractional then quote the values, otherwise you will loose precision
'example: pi="3.1415926535897932384626433832795029"
'without the Q
'sometimes you may need to convert an integer to float128, for example
'y = float128(1)/3
'as long as one of the operands is of the type float128 the operation is performed in quad precision
'but it needs to be done for each operation that uses constants only, for example
'y=float128(1)-float128(1)/3+float128(1)/5-float128(1)/7+float128(1)/9
'or
'y=float128(1)
'y=y-y/3+y/5-y/7+y/9
Print "sin(float128(1)) = ";sin(float128(1))
Print "x+y = ";x+y
Print "x-y = ";x-y
Print "x*y = ";x*y
Print "x/y = ";x/y
Print "x^y = ";x^y
x="31415926535897932384626433832.795029"
Print "x=""31415926535897932384626433832.795029"""
print "int(x) = ";int(x)
print "frac(x) = ";frac(x)
Print
for x=2 to 10 ' quad loop variable
   y=sqr(x)
   'Print x
   'Print x.toLong, y.toString
   Print x.toLong, y.toString("%20.16e")
   'Print x.toLong, y.toString("%20.16f")
   'Print x.toLong, y.toString("%20.16g")
next
Print "press return to continue ";
Sleep


on different versions of freebasic


on 1.07.1 both sin and sqrt gives other results:
This is the raw output:


Freebasic32 bit Version 1.00.0 to Version 1.05.0:

x = 6.95340896834890104578573111523925e-4957
y = 6.95356810225263635469085719425109e-4957
sin(float128(1)) = 1.78795510411013371293505820035385e+689
x+y = 6.95393941469468540880281804527871e-4957
x-y = 2.0857999030394408812685428239552e-4956
x*y = 6.95477486768929578055472996009086e-4957
x/y = -2.30781347570055898808106592728065e+2740
x^y = -9.68682895498430420543074935362482e-2197
x="31415926535897932384626433832.795029"
int(x) = -3.89920737096359799729748529729058e-3326
frac(x) = 6.95206802433341662516550977317539e-4957

2 2.648594657018866e-3437
3 9.424731734583207e-1431
4 1.282540566677892e-4937
5 -2.159776199930572e+29
6 3.919099755947279e-3376
7 -2.181099074525341e+3935
8 2.648594657340662e-3437
9 1.282579706709834e-4937
10 -3.280473103595770e+631
press return to continue





Freebasic32 bit Version 1.07.1:

x = 1.28267755678968937532612292666873e-4937
y = 1.28270691181364593108437307061072e-4937
sin(float128(1)) = -2.26050992680938428006536093257871e+1393
x+y = 1.2827754068695445611869567398087e-4937
x-y = 3.84762170003367634536286676481829e-4937
x*y = 1.28292952074531647891776999550416e-4937
x/y = 2.0763231973385187308911533586517e-548
x^y = 1.2844351501948090833444884140479e-4937
x="31415926535897932384626433832.795029"
int(x) = 1.93448054686427437623258682818866e+4672
frac(x) = 1.28243019627898124007319233141534e-4937

2 -1.040924649386231e+2960
3 -2.361980583444375e-1347
4 6.952666343464803e-4957
5 6.259858679043400e+4448
6 -7.318447307655135e+2562
7 -2.138529798262719e+4517
8 -1.040924649386231e+2960
9 6.952878522003117e-4957
10 -5.147288135946323e-4649
press return to continue



The presence of line : x="31415926535897932384626433832.795029"
garbles all results on a win7 machine.
removal of the line gives:




Freebasic32 bit Version 1.00.0 to Version 1.05.0:
x = 7
y = 9
sin(float128(1)) = 0.841470984807896506652502321630299
x+y = 16
x-y = -2
x*y = 63
x/y = 0.777777777777777777777777777777778
x^y = 40353607
int(x) = 7
frac(x) = 0
2 -3.255442717985002e+696
3 -3.381639360952167e-1909
4 2.986147456518123e-4947
5 5.417344683920655e+4630
6 -2.994789343894694e+3068
7 -2.228906656727438e-2815
8 -3.255442717985002e+696
9 2.986238586506420e-4947
10 3.800794403875165e-1763
press return to continue


Freebasic32 bit Version 1.07.1:
x = 2.98646641147716291091899137634022e-4947
y = 2.98653475896838570731778878395148e-4947
sin(float128(1)) = -1.25071669150585757230911198314797e+2486
x+y = 2.98669423644790556558164940171107e-4947
x-y = 8.95844236955436958317381042246309e-4947
x*y = 2.98705306077682524667533579167016e-4947
x/y = -1.78226248556146627528980210075403e-3836
x^y = 2.99055862751512109149361125670349e-4947
int(x) = 2.98646641147716291091899137634022e-4947
frac(x) = 0

2 1.414213562373095e+00
3 1.732050807568877e+00
4 2.000000000000000e+00
5 2.236067977499790e+00
6 2.449489742783178e+00
7 2.645751311064591e+00
8 2.828427124746190e+00
9 3.000000000000000e+00
10 3.162277660168379e+00
press return to continue


It seems strtoflt128(,) does have some more issues independent of Freebasic versions.
also note version <1.07.0 tostring produces wrong y=sqr(x), but internally y is correct


Regards, C
srvaldez
Posts: 2327
Joined: Sep 25, 2005 21:54

Re: using gcc quadmath

Postby srvaldez » Apr 07, 2020 9:45

Hi codelab
thank you for the detailed report, let me rebuild the dll with a later version of gcc and see if it works as it should
am also thinking of using other code to do the string/float conversions, but lets try this first
will post a link within an hour or so.
srvaldez
Posts: 2327
Joined: Sep 25, 2005 21:54

Re: using gcc quadmath

Postby srvaldez » Apr 07, 2020 10:52

@codelab
please try this QuadMath
srvaldez
Posts: 2327
Joined: Sep 25, 2005 21:54

Re: using gcc quadmath

Postby srvaldez » Apr 07, 2020 20:23

Hi codelab
I updated the dll's and import libs, please replase the dll's and the import lib's with the new ones and try the examples quad-math-test3d and quad-math-test3f
I am going to be away from my PC for the next 8 or 9 days, but don't hesitate to post, there are other friendly member that can assist
codelab
Posts: 8
Joined: Mar 31, 2020 11:47

Re: using gcc quadmath

Postby codelab » Apr 08, 2020 9:01

Hi Srvaldez

Thanks for building the dll's.
They solved the issue, I tested it on 5 platforms (4x32 bit /1x64bit and everythings is similar and fine.


Code: Select all

#include "quadmath.bi"

dim as float128 x, y, z

x=7 : Print "x = ";x
y=9 : Print "y = ";y
'if the values are fractional then quote the values, otherwise you will loose precision
'example: pi="3.1415926535897932384626433832795029"
'without the Q
'sometimes you may need to convert an integer to float128, for example
'y = float128(1)/3
'as long as one of the operands is of the type float128 the operation is performed in quad precision
'but it needs to be done for each operation that uses constants only, for example
'y=float128(1)-float128(1)/3+float128(1)/5-float128(1)/7+float128(1)/9
'or
'y=float128(1)
'y=y-y/3+y/5-y/7+y/9
Print "sin(float128(1)) = ";sin(float128(1))
Print "x+y = ";x+y
Print "x-y = ";x-y
Print "x*y = ";x*y
Print "x/y = ";x/y
Print "x^y = ";x^y

Print "sqr(x) = ";Sqr(x)
 
x="31415926535897932384626433832.795029"
Print "x=""31415926535897932384626433832.795029"""
print "int(x) = ";int(x)
print "frac(x) = ";frac(x)
 
 
for x=2 to 10 ' quad loop variable
   
   y=sqr(x)
   Print y
Next
Print "press return to continue ";
Sleep


Output from differnet versions:
FB32V100.0 + FB32V104.0 + FB32V105.0 + FB32V107.0 + FB64V107.0:

x = 7.000000000000000000000000000000000E0
y = 9.000000000000000000000000000000000E0
sin(float128(1)) = 8.414709848078965066525023216302990E-1
x+y = 1.600000000000000000000000000000000E1
x-y = -2.000000000000000000000000000000000E0
x*y = 6.300000000000000000000000000000000E1
x/y = 7.777777777777777777777777777777778E-1
x^y = 4.035360700000000000000000000000000E7
sqr(x) = 2.645751311064590590501615753639260E0
x="31415926535897932384626433832.795029"
int(x) = 3.141592653589793238462643383200000E28
frac(x) = 7.950286865234375000000000000000000E-1
1.414213562373095048801688724209698E0
1.732050807568877293527446341505872E0
2.000000000000000000000000000000000E0
2.236067977499789696409173668731276E0
2.449489742783178098197284074705892E0
2.645751311064590590501615753639260E0
2.828427124746190097603377448419396E0
3.000000000000000000000000000000000E0
3.162277660168379331998893544432719E0
press return to continue



Now its really good :)

Regards, C

Return to “General”

Who is online

Users browsing this forum: No registered users and 6 guests