
\ -----------------------------------------------------------------------------
\   Accuracy testing
\   Save the output as sinetable.dat, replace all commas with dots and check with Gnuplot:
\
\   Results:
\     plot "sinetable.dat" u 1:2 w l, "sinetable.dat" u 1:(sin($1)) w l
\     plot "sinetable.dat" u 1:3 w l, "sinetable.dat" u 1:(cos($1)) w l
\   Errors:
\     plot "sinetable.dat" u 1:($2 - sin($1)) w l
\     plot "sinetable.dat" u 1:($3 - cos($1)) w l
\ -----------------------------------------------------------------------------

4096 constant sinesamples

: sinetable ( -- )

  cr
  sinesamples 0 do
    i s>f pi 2,0 f* f*
    sinesamples s>f f/

    2dup f.

    2dup widesine f.
         widecosine f.
    cr
  loop
  cr
;

\ -----------------------------------------------------------------------------
\   Accuracy testing
\   Save the output as arcsin.dat, replace all commas with dots and check with Gnuplot:
\
\   Results:
\     plot "arcsin.dat" u 1:2 w l, "arcsin.dat" u 1:(asin($1)) w l
\   Errors:
\     plot "arcsin.dat" u 1:($2 - asin($1)) w l
\ -----------------------------------------------------------------------------

: arcsin-test ( -- )

  cr
  sinesamples 1+ 0 do
    i s>f 2,0 f*
    sinesamples s>f f/
    1,0 d-

    2dup f.

    2dup arcsin f.
         arccos f.
    cr
  loop
  cr
;  

\ -----------------------------------------------------------------------------
\   Show a few arctangents
\ -----------------------------------------------------------------------------

  : p. xy>polar  d.  180,0 pi f/ f* f. cr ;
\ : p. atan2 180,0 pi f/ f* f. cr ;
\ : p. magnitude d. cr ;

 10000      0 p.  ( 0 )
 10000  10000 p.  ( 45 )
     0  10000 p.  ( 90 )
-10000  10000 p.  ( 135 )
-10000      0 p.  ( +-180 )
-10000 -10000 p.  ( -135 )
     0 -10000 p.  ( -90 )
 10000 -10000 p.  ( -45 )


 10   0 p.  ( 0 )
 10  10 p.  ( 45 )
  0  10 p.  ( 90 )
-10  10 p.  ( 135 )
-10   0 p.  ( +-180 )
-10 -10 p.  ( -135 )
  0 -10 p.  ( -90 )
 10 -10 p.  ( -45 )

\ -----------------------------------------------------------------------------
\   Accuracy testing
\   Save the output as atan2-test.dat, replace all commas with dots and check with Gnuplot:
\
\   Probed values:
\     plot "atan2-test.dat" u 1:2 w p
\   Results:
\     plot "atan2-test.dat" u 0:4 w l, "atan2-test.dat" u 0:(atan2($2, $1)/pi*180) w l
\     plot "atan2-test.dat" u 0:3 w l, "atan2-test.dat" u 0:(sqrt($2*$2 + $1*$1)) w l
\   Errors:
\     plot "atan2-test.dat" u 0:($4 - atan2($2, $1)/pi*180) w l
\     plot "atan2-test.dat" u 0:($3 - sqrt($2*$2 + $1*$1))  w l
\ -----------------------------------------------------------------------------

: atan2-test ( -- )
  cr cr

  100000 -100000 do  i  10000    2dup swap . .   p. 100 +loop
  100000 -100000 do  i -10000    2dup swap . .   p. 100 +loop

  100000 -100000 do     10000 i  2dup swap . .   p. 100 +loop
  100000 -100000 do    -10000 i  2dup swap . .   p. 100 +loop

  cr cr
;

 
