### Author Topic: GCC QuadMath library - REAL16 math  (Read 4593 times)

#### jj2007

• Moderator
• Member
•     • • Posts: 10264
• Assembler is fun ;-) ##### GCC QuadMath library - REAL16 math
« on: August 17, 2017, 10:28:30 AM »
Attached a testbed for the QuadMath lib - about 90 functions. Building requires MasmBasic 17 August and a 32-bit GCC installation.

It seems to work so far (in the sense: with arbitrary numbers, it doesn't throw exceptions), but my math skills are clearly not good enough. Unfortunately, the documentation for that library is lousy. Does anybody know enough about these functions to design meaningful tests?

Code: [Select]
`3.16227766016837933199889354443272e-01Complex numbers:-0.300000000000000000000000000000000r   0.100000000000000000000000000000000i-0.500000000000000000000000000000000r   0.200000000000000000000000000000000i1       6.79675056344163539816123196439774e-01    Quad\$(QuadMath(acosq, f128_1))       arc cosine function2       -nan                                      Quad\$(QuadMath(acoshq, f128_1))      inverse hyperbolic cosine function3       8.91121270450733079415198495199977e-01    Quad\$(QuadMath(asinq, f128_1))       arc sine function4       7.15220808521240713368180068139420e-01    Quad\$(QuadMath(asinhq, f128_1))      inverse hyperbolic sine function5       6.61042684235119596446884984928197e-01    Quad\$(QuadMath(atanq, f128_1))       arc tangent function6       1.03971880209293260540357689630520e+00    Quad\$(QuadMath(atanhq, f128_1))      inverse hyperbolic tangent function7       7.18829999621624505417014151525905e-01    Quad\$(QuadMath(atan2q, f128_1, f128  arc tangent function8       9.19641085579807331708184954882012e-01    Quad\$(QuadMath(cbrtq, f128_1))       cube root function9       1.00000000000000000000000000000000e+00    Quad\$(QuadMath(ceilq, f128_1))       ceiling value function10      7.77777000000000000000000000000000e-01    Quad\$(QuadMath(copysignq, f128_1, f  copy sign of a number11      1.31802721007488863001046816772184e+00    Quad\$(QuadMath(coshq, f128_1))       hyperbolic cosine function12      7.12475170303218178481897562102759e-01    Quad\$(QuadMath(cosq, f128_1))        cosine function13      7.28642947148188881602143870565993e-01    Quad\$(QuadMath(erfq, f128_1))        error function14      2.71357052851811118397856129434007e-01    Quad\$(QuadMath(erfcq, f128_1))       complementary error function15      2.17662823878251521093957473563285e+00    Quad\$(QuadMath(expq, f128_1))        exponential function16      1.17662823878251521093957473563285e+00    Quad\$(QuadMath(expm1q, f128_1))      exponential minus 1 function17      7.77777000000000000000000000000000e-01    Quad\$(QuadMath(fabsq, f128_1))       absolute value function18      0.00000000000000000000000000000000e+00    Quad\$(QuadMath(fdimq, f128_1, f128_  positive difference function19      1                                         Str\$(QuadMath(finiteq, f128_1))      check finiteness of value20      0.00000000000000000000000000000000e+00    Quad\$(QuadMath(floorq, f128_1))      floor value function21      1.69135564197599999999999999999999e+00    Quad\$(QuadMath(fmaq, f128_1, f128_2  fused multiply and add22      8.88887999999999999999999999999999e-01    Quad\$(QuadMath(fmaxq, f128_1, f128_  determine maximum of two values23      7.77776999999999999999999999999999e-01    Quad\$(QuadMath(fminq, f128_1, f128_  determine minimum of two values24      7.77776999999999999999999999999999e-01    Quad\$(QuadMath(fmodq, f128_1, f128_  remainder value function25      7.77776999999999999999999999999999e-01    Quad\$(QuadMath(frexpq, f128_1, &int  extract mantissa and exponent26      1.18112613139875963037219043508971e+00    Quad\$(QuadMath(hypotq, f128_1, f128  Eucledian distance function27      0                                         Str\$(QuadMath(isinfq, f128_1))       check for infinity28      -1                                        Str\$(QuadMath(ilogbq, f128_1))       get exponent of the value29      0                                         Str\$(QuadMath(isnanq, f128_1))       check for not a number30      8.54388504707771712092309739814944e-01    Quad\$(QuadMath(j0q, f128_1))         Bessel function of the first kind, first order31      3.60213810637432487067489691829813e-01    Quad\$(QuadMath(j1q, f128_1))         Bessel function of the first kind, second order33      7.77776999999999999999999999999999e-01    Quad\$(QuadMath(ldexpq, f128_1))      load exponent of the value34      1.74081138059681937201628653041458e-01    Quad\$(QuadMath(lgammaq, f128_1))     logarithmic gamma function35      0                                         Str\$(QuadMath(llrintq, f128_1))      round to nearest integer value36      1                                         Str\$(QuadMath(llroundq, f128_1))     round to nearest integer value away from zero37      -2.51315428281406078018471313735404e-01   Quad\$(QuadMath(logq, f128_1))        natural logarithm function38      -1.09144903719767094515383760835130e-01   Quad\$(QuadMath(log10q, f128_1))      base 10 logarithm function39      -3.62571522080470492430259119929199e-01   Quad\$(QuadMath(log2q, f128_1))       base 2 logarithm function40      5.75363707403466151725524591370230e-01    Quad\$(QuadMath(log1pq, f128_1))      compute natural logarithm of the value plus one41      0                                         Str\$(QuadMath(lrintq, f128_1))       round to nearest integer value42      1                                         Str\$(QuadMath(lroundq, f128_1))      round to nearest integer value away from zero43      7.77776999999999999999999999999999e-01    Quad\$(QuadMath(modfq, f128_1, OWORD  decompose the floating-point number44      nan                                       Quad\$(QuadMath(nanq, dword PTR [ebx  return quiet NaN45      0.00000000000000000000000000000000e+00    Quad\$(QuadMath(nearbyintq, f128_1))  round to nearest integer46      7.77776999999999999999999999999999e-01    Quad\$(QuadMath(nextafterq, f128_1,   next representable floating-point number47      1.00000000000000000000000000000000e+00    Quad\$(QuadMath(powq, f128_1, f128_2  power function48      -nan                                      Quad\$(QuadMath(remainderq, f128_1,   remainder function49      -nan                                      Quad\$(QuadMath(remquoq, f128_1, f12  remainder and part of quotient50      0.00000000000000000000000000000000e+00    Quad\$(QuadMath(rintq, f128_1))       round-to-nearest integral value51      1.00000000000000000000000000000000e+00    Quad\$(QuadMath(roundq, f128_1))      round-to-nearest integral value, return __float12852      7.77776999999999999999999999999999e-01    Quad\$(QuadMath(scalblnq, f128_1))    compute exponent using FLT_RADIX53      7.77776999999999999999999999999999e-01    Quad\$(QuadMath(scalbnq, f128_1))     compute exponent using FLT_RADIX54      0                                         Str\$(QuadMath(signbitq, f128_1))     return sign bit55_     7.77776999999999999999999999999999e-01    QuadMath(sincosq, f128_1, OWORD PTR  calculate sine and cosine simultaneously56      8.58601028707626580929106567911009e-01    Quad\$(QuadMath(sinhq, f128_1))       hyperbolic sine function57      7.01697321999592822577494428203881e-01    Quad\$(QuadMath(sinq, f128_1))        sine function58      8.81916662729534779709025956238766e-01    Quad\$(QuadMath(sqrtq, f128_1))       square root function59      9.84872668195526766344208902855793e-01    Quad\$(QuadMath(tanq, f128_1))        tangent function60      6.51428909922764009034212653601591e-01    Quad\$(QuadMath(tanhq, f128_1))       hyperbolic tangent function61      1.19015212853728978240171569191066e+00    Quad\$(QuadMath(tgammaq, f128_1))     true gamma function62      0.00000000000000000000000000000000e+00    Quad\$(QuadMath(truncq, f128_1))      round to integer, towards zero63      -1.08823755104290320639507753297712e-01   Quad\$(QuadMath(y0q, f128_1))         Bessel function of the second kind, first order64      -1.00388964645596038174697269505841e+00   Quad\$(QuadMath(y1q, f128_1))         Bessel function of the second kind, second order65      -inf                                      Quad\$(QuadMath(ynq, f128_1))         Bessel function of the second kind, n-th order66      1.11111100000000000000000000000000e+00    Quad\$(QuadMath(cabsq, c128_1))       complex absolute value function67      0.00000000000000000000000000000000e+00    Quad\$(QuadMath(cargq, c128_2))       calculate the argument68      0.00000000000000000000000000000000e+00    Quad\$(QuadMath(cimagq, c128_1))      imaginary part of complex number69      1.11111100000000000000000000000000e+00    Quad\$(QuadMath(crealq, c128_1))      real part of complex number70      0.00000000000000000000000000000000e+00    Quad\$(QuadMath(cacosq, c128_1))      complex arc cosine function71      4.67145078687467774975308067585712e-01    Quad\$(QuadMath(cacoshq, c128_1))     complex arc hyperbolic cosine function72      1.57079632679489661923132169163975e+00    Quad\$(QuadMath(casinq, c128_1))      complex arc sine function73      9.57800374871255507537319505105416e-01    Quad\$(QuadMath(casinhq, c128_1))     complex arc hyperbolic sine function74      8.37981175284630374344180916658704e-01    Quad\$(QuadMath(catanq, c128_1))      complex arc tangent function75      1.47221996326768006396617005905066e+00    Quad\$(QuadMath(catanhq, c128_1))     complex arc hyperbolic tangent function76      4.43666121279137034963262698715523e-01    Quad\$(QuadMath(ccosq, c128_1))       complex cosine function77      1.68346223218832726875681425264904e+00    Quad\$(QuadMath(ccoshq, c128_1))      complex hyperbolic cosine function78      3.03773143999174827676530639951211e+00    Quad\$(QuadMath(cexpq, c128_1))       complex exponential function79      7.12475170303218178481897562102759e-01    Quad\$(QuadMath(cexpiq, f128_1))      computes the exponential function of "i" times a real value80      1.05360415657821301227167647480979e-01    Quad\$(QuadMath(clogq, c128_1))       complex natural logarithm81      4.57574471312247636122071472795808e-02    Quad\$(QuadMath(clog10q, c128_1))     complex base 10 logarithm82      1.11111100000000000000000000000000e+00    Quad\$(QuadMath(conjq, c128_1))       complex conjugate function83      1.00000000000000000000000000000000e+00    Quad\$(QuadMath(cpowq, c128_1, c128_  complex power function84      1.11111100000000000000000000000000e+00    Quad\$(QuadMath(cprojq, c128_1))      project into Riemann Sphere85      8.96192151733726168465708950029809e-01    Quad\$(QuadMath(csinq, c128_1))       complex sine function86      1.35426920780342100800849214686307e+00    Quad\$(QuadMath(csinhq, c128_1))      complex hyperbolic sine function87      1.05409250068483079024421803054925e+00    Quad\$(QuadMath(csqrtq, c128_1))      complex square root88      2.01996976724278164327568071148291e+00    Quad\$(QuadMath(ctanq, c128_1))       complex tangent function89      8.04454761092567379921780988485073e-01    Quad\$(QuadMath(ctanhq, c128_1))      complex hyperbolic tangent function------------- all done -------------`

#### nidud

• Member
•     • Posts: 1928 ##### Re: GCC QuadMath library - REAL16 math
« Reply #1 on: August 17, 2017, 11:16:01 AM »
So, from Wiki:

Quote
4000 921f b544 42d1 8469 898c c517 01b8 =
3.1415926535897932384626433832795028

Test case

Code: [Select]
`#include <stdio.h>#include <quadmath.h>int main(void){    __float128 q = 3.1415926535897932384626433832795028;    __int64   *p = (__int64 *)&q;    printf("%p%p - gcc\n", p,p);    return 0;}`
Code: [Select]
`include stdio.inc.datax real10 3.1415926535897932384626433832795028y real16 3.1415926535897932384626433832795028.codemain proc    lea edx,y    printf("%p%p%p%p - REAL16\n",[edx+12],[edx+8],[edx+4],[edx]);    lea edx,x    movzx eax,word ptr [edx+8]    mov ecx,[edx+4]    mov edx,[edx]    shl edx,1    rcl ecx,1    printf("%04X%p%pxxxxxxxxxxxx - REAL10\n",eax,ecx,edx);    retmain endp    end main`
output:
Code: [Select]
`4000921FB54442D18469898CC51701B8 - REAL164000921FB54442D1846Axxxxxxxxxxxx - REAL104000921FB54442D18000000000000000 - gcc`
So is it "real" or do they just use the FPU?

#### TWell

• Member
•    • Posts: 748 ##### Re: GCC QuadMath library - REAL16 math
« Reply #2 on: August 17, 2017, 02:55:51 PM »
__float128 q = 3.1415926535897932384626433832795028q;

#### jj2007

• Moderator
• Member
•     • • Posts: 10264
• Assembler is fun ;-) ##### Re: GCC QuadMath library - REAL16 math
« Reply #3 on: August 17, 2017, 06:08:19 PM »
__float128 q = 3.1415926535897932384626433832795028q;

Indeed :t

SetGlobals MyPI:REAL16

PrintLine "digits", Tb\$, "1.23456789012345678901234567890123"
PrintLine "PI", Tb\$, "3.14159265358979323846264338327950", Tb\$, "(as text)"

PrintLine "MyPI", Tb\$, Quad\$(MyPI, g), Tb\$, "Real16 precision"

Inkey "MyPI", Tb\$, Quad\$(MyPI, g), Tb\$, "Real10 precision"

EndOfCode

Code: [Select]
`digits  1.23456789012345678901234567890123PI      3.14159265358979323846264338327950      (as text)MyPI    3.14159265358979323846264338327950      Real16 precisionMyPI    3.14159265358979323851280895940619      Real10 precision`
But that is under control, thanks. I am more interested in the more complicated math stuff...

#### nidud

• Member
•     • Posts: 1928 ##### Re: GCC QuadMath library - REAL16 math
« Reply #4 on: August 17, 2017, 09:36:20 PM »
Yes, that works  :t
Code: [Select]
`    __float128 q = 31415926535897932384626433832795028q-34;4000921FB54442D18469898CC51701B8 - REAL164000921FB54442D18469898CC51701B8 - gcc`
https://software.intel.com/en-us/node/678511
Quote
Valid REAL(16) Constants

123456789Q4000
-1.23Q-400
+2.72Q0
1.88_16

#### Siekmanski

• Member
•     • • Posts: 2131 ##### Re: GCC QuadMath library - REAL16 math
« Reply #5 on: August 18, 2017, 12:03:20 AM »
Does anybody know enough about these functions to design meaningful tests?

Most of the functions can be used in high precision Digital Signal Processing.
Ask Raistlin, AFAIK he does calculations on pulsar data.
Creative coders use backward thinking techniques as a strategy.

#### jj2007

• Moderator
• Member
•     • • Posts: 10264
• Assembler is fun ;-) ##### Re: GCC QuadMath library - REAL16 math
« Reply #6 on: August 19, 2017, 11:50:44 AM »
Thanks, Marinus.

Just discovered that C:\Windows\System32\calc.exe uses quad precision. But PEView doesn't give any hint to an undocumented Windows quadmath DLL :(

So they do it probably with a tiny part of the 776,192 bytes of calc.exe...

#### TWell

• Member
•    • Posts: 748 ##### Re: GCC QuadMath library - REAL16 math
« Reply #7 on: August 19, 2017, 03:20:04 PM »
Quote
In Windows 98 and later, it uses an arbitrary-precision arithmetic library
https://en.wikipedia.org/wiki/Windows_Calculator

#### jj2007

• Moderator
• Member
•     • • Posts: 10264
• Assembler is fun ;-) ##### Re: GCC QuadMath library - REAL16 math
« Reply #8 on: August 19, 2017, 07:28:16 PM »
Yes, but they don't tell you which one :(

The Wiki has a link to a defunct "calc plus" page:
Quick Details
File Name:   CalcPlus.msi
...
Good ol' times :P

#### mabdelouahab

• Member
•   • Posts: 449 ##### Re: GCC QuadMath library - REAL16 math
« Reply #9 on: October 21, 2017, 03:04:27 AM »
Quote
I've installed the version tdm-gcc-5.1.0

#### jj2007

• Moderator
• Member
•     • • Posts: 10264
• Assembler is fun ;-) ##### Re: GCC QuadMath library - REAL16 math
« Reply #10 on: October 21, 2017, 03:10:38 AM »
Try Init dynaquad (that forces using the DLLs, which should always be in the same location).

If that doesn't work, try inserting this line before Init:

There are more constants that can be adapted, but normally you shouldn't touch them:

GccStatic\$ equ      <libgcc.a>
GccDll\$ equ      <libgcc_s_dw2-1>

#### mabdelouahab

• Member
•   • Posts: 449 ##### Re: GCC QuadMath library - REAL16 math
« Reply #11 on: October 21, 2017, 05:47:37 AM »
Try Init dynaquad (that forces using the DLLs, which should always be in the same location).
It works, thanks :t

#### jj2007

• Moderator
• Member
•     • • Posts: 10264
• Assembler is fun ;-) ##### Re: GCC QuadMath library - REAL16 math
« Reply #12 on: October 21, 2017, 06:54:57 AM »
The static version should work, too. It will give you plenty of warnings of the type "POLINK: warning: Section name '.debug_info' is longer than 8 characters; truncated." but they can be ignored.

In RichMasm, File/New Masm source opens a list of templates; towards the bottom is a QuadMath example; I just remembered that Quad(immediate) is no longer necessary, i.e. you can use the immediate REAL16 directly:

#### LiaoMi ##### Re: GCC QuadMath library - REAL16 math
« Reply #13 on: October 21, 2017, 11:51:47 PM »
Hi,

here is the latest version libquadmath_x32_x64_gcc-7_2_0 https://mega.co.nz/#!VxQhGYiZ!AAAAAAAAAACUIvLONoOxdwAAAAAAAAAAlCLyzjaDsXc from the msys package, with headers #### jj2007

• Moderator
• Member
•     • • Posts: 10264
• Assembler is fun ;-) ##### Re: GCC QuadMath library - REAL16 math
« Reply #14 on: October 22, 2017, 01:50:23 AM »
Code: [Select]
`  QuadLibDynaP\$ equ <\Masm32\MasmBasic\Members\LiaoMi\x32\> ; path to the DLLs  Init dynaquad ; use dynaquad to link the DLLs dynamically`
Works fine, thanks. Any big difference to the previous version? The new ones are a few kBytes shorter.