Author Topic: why does g++ option -mfpmath=387 have no effect?  (Read 3204 times)

0 Members and 1 Guest are viewing this topic.

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
why does g++ option -mfpmath=387 have no effect?
« on: December 05, 2019, 02:56:08 pm »
while running a floating-point progie, I noticed poor accuracy in the print-out, so I added -mfpmath=387 to makeline_win.txt but the result is the same, anyone knows why?
running QB64 x64 on Windows
the same program in C works as expected
« Last Edit: December 05, 2019, 02:58:01 pm by jack »

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: why does g++ option -mfpmath=387 have no effect?
« Reply #1 on: December 05, 2019, 07:16:24 pm »
here's the test code
Code: [Select]
$CONSOLE:ONLY
_DEST _CONSOLE

DIM x AS DOUBLE

FOR x = 0 TO 17
    PRINT x, gamma(x)
NEXT

FUNCTION gamma# (z AS DOUBLE)
    '' minimax approximation in the range 0 to 140
    gamma = ((6.5509757416010777593d10+_
        (5.9509245152044405705d10+_
        (2.4326261621014728055d10+_
        (5.8928108119886118679d9+_
        (9.3678283088322428701d8+_
        (1.0211711437792197690d8+_
        (7.7302875846952982533d6+_
        (4.0126933328085900555d5+_
        (13669.279342201901514d0+_
        (275.93799589896263864d0+_
        2.5066282746310005024d0*z)*z)*z)*z)*z)*z)*z)*z)*z)*z)*(z+11d0)^(z+0.5d0)_
        *exp(-z-11d0)/(3628800d0+(10628640d0+(12753576d0+(8409500d0+(3416930d0+_
        (902055d0+(157773d0+(18150d0+(1320d0+(55d0+z)*z)*z)*z)*z)*z)*z)*z)*z)*z))
END FUNCTION
output with QB64 32-bit
Code: [Select]
0        1
 1        1
 2        2
 3        6
 4        24
 5        120
 6        720
 7        5040
 8        40320
 9        362880
 10       3628800
 11       39916800
 12       479001600
 13       6227020800
 14       87178291200
 15       1307674368000
 16       20922789888000
 17       355687428096000
output with QB64 64-bit
Code: [Select]
0        1
 1        .9999999999999998
 2        2.000000000000001
 3        6
 4        24
 5        120
 6        720
 7        5040.000000000001
 8        40319.99999999994
 9        362879.9999999995
 10       3628800.000000004
 11       39916799.99999993
 12       479001599.9999987
 13       6227020799.999996
 14       87178291200.00023
 15       1307674368000.004
 16       20922789888000.04
 17       355687428096001.8

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: why does g++ option -mfpmath=387 have no effect?
« Reply #2 on: December 06, 2019, 11:16:36 am »
Oh Gamma function is a factorial estimator? G(n) = (n-1)! when n is positive integer.
This calculator: https://www.numberempire.com/gammafunctioncalculator.php

 has Gamma(3) = 2, Gamma(4) = 6... your whole table is off, with 0 not even being doable according to this link.

_ROUND( the whole calc )  gets rid of the garbage collection at the end of decimal until your gamma(17), it would probably do better if it were properly inserted in the calculation to cut off the garbage building up in the computations.

Have you tried _FLOAT?

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: why does g++ option -mfpmath=387 have no effect?
« Reply #3 on: December 06, 2019, 12:21:42 pm »
Have you tried _FLOAT?
yes, _float works to some extent in 32-bit but not in 64-bit
the function posted above is for gamma(1+x), so it's the same as factorial but valid for fractional arguments, so _round is not the solution
I am just disappointed that the precision is so poor in 64-bit.