Floating point options in Linux

Home Forums SwiftForth Forum Floating point options in Linux

This topic contains 5 replies, has 2 voices, and was last updated by  Roelf 8 months, 1 week ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #13195

    rogerlevy
    Participant

    I am getting different behavior on some floating path ops such as fatan2 than on Windows. I wanted to see if there were any configuration options to solve this but the section in the docs on this is marked TBD, so right now I’m at a wall.

    #13197

    Roelf
    Participant

    Hi Roger,

    Which version of sf are you using? As of SwiftForth-3.6.2 (04-Apr-2016)
    FATAN is fixed (thanks to George Kozlowski). FATAN2 is fixed as well.
    Both are now the Intel versions (similar to VFX and iForth).
    Current version:

    
    CODE FATAN ( -- ) ( r1 -- r2 )   >f   FLD1  FPATAN   f>   FNEXT
    CODE FATAN2 ( -- ) ( y x -- r )   2 >fs   FPATAN   f>   FNEXT
    

    You can verify with the FATAN2 output from this C library function:

    
    FUNCTION: atan2 ( n n n n -- )
    : CATAN2  ( -- ; F: r r -- r )   2fstack>stack   atan2   st0> ;
    

    Which uses words from George’s fp-passing.f in SwiftForth/lib/options/osx. These might work in Linux as well.

    #13673

    rogerlevy
    Participant

    Thanks for the info. I simply adapted my code to work with the fixed FATAN2.

    I’m now running into a very familiar issue with calling external C functions that use floating point. With astounding inscrutability, some of my calls will throw errors such as “Numeric stack error” and “No floating point number to print”

    I don’t know I fixed this in the past though. Maybe by enabling the hardware float stack, it’s been a while … on Windows I know how to do it in the IDE. How would I do this on Linux?

    #13674

    rogerlevy
    Participant

    (BTW, I am putting my floats on the data stack prior to calling)

    #13678

    Roelf
    Participant

    It needs a bit of work. AFAIK the current FUNCTION: only uses the datastack. For OSX, George Kozlowski created fp-passing.f This might work for Linux as well, you could try.

    In your SwiftForth Linux/OSX distribution:
    SwiftForth/lib/options/osx/fp-passing.f

    Example of an external C function that use floating point:

    
    \ extern double j0 ( double );
    FUNCTION: j0 ( n n — )
    -? : j0 ( — ; F: r — r )
    fstack>stack j0 st0> ;
    { —————————————————————————
    2e0 j0 f. 0.2238907 ok
    3e0 j0 f. -0.2600519 ok
    ————————————————————————— }
    

    (See posting “FUNCTION: with floating point”)

    #13687

    Roelf
    Participant

    Perhaps useful: pass floats as 32bit sfloats. Have to do this on the mac a lot.

    
    CODE F>SF ( -- sfloat ) ( F: r -- )
       >f
       4 # EBP SUB
       0 [EBP] DWORD FSTP
       EBX EAX MOV
       0 [EBP] EBX MOV
       EAX 0 [EBP] MOV
       FNEXT
    
    CODE SF>F ( sfloat -- ) ( F: -- r )
       EBX EAX MOV
       0 [EBP] EBX MOV
       EAX 0 [EBP] MOV
       0 [EBP] DWORD FLD
       4 # EBP ADD
       f>
       FNEXT
    
    \ for completeness
    AKA FSTACK>STACK    F>DF ( -- dfloat )  ( F: r -- )
    AKA STACK>FSTACK    DF>F ( dfloat -- )  ( F: -- r )
    

    There’s a whole zoo of these words in the latest SF distro:
    %SwiftForth/lib/samples/osx/mac/utils/fp-precision-fast.f
    %SwiftForth/lib/samples/osx/mac/utils/fp-utils.f

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.