Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Forth > Re: Taylor seri...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 6 Topic 4019 of 4053
Post > Topic >>

Re: Taylor series FSIN, FCOS, FTAN

by "The Beez'" <hansoft@[EMAIL PROTECTED] > Apr 27, 2008 at 08:45 AM

Albert,

I think I figured it out (your routine). This feels quite good (and
the test ranges come back fine too ;-)

Hans Bezemer

[UNDEFINED] fsin [IF]
[UNDEFINED] floats [IF]
include lib/ansfloat.4th
[THEN]

: >range
  pi fdup f+                           \ x pi2
  fover fover f/                       \ x pi2 x/pi2
  floor fover f*                       \ x pi2 mod(x,pi2)
  frot fswap f-                        \ pi2 mod(x,pi2)
  pi fover                             \ pi2 mod pi mod
  f- f0< if fswap f- else fnip then
;

: f-rot frot frot ;                    \ inverted frot
: >taylor fdup f* fover ;              \ setup for Taylor series
: (taylor) fover f* frot fover s>f f/ ;
: +taylor (taylor) f+ f-rot ;          \ add Taylor iteration
: -taylor (taylor) f- f-rot ;          \ subtract Taylor iteration

: fsin
  >range fdup >taylor                  ( x x2 x)
         6 -taylor                     ( x-3 x2 x3)
       120 +taylor                     ( x+5 x2 x5)
      5040 -taylor                     ( x-7 x2 x7)
    362880 +taylor                     ( x+9 x2 x9)
  39916800 -taylor                     ( x-11 x2 x11)
  fdrop fdrop                          ( x-11)
;

: fcos
  1 s>f fswap >range >taylor           ( 1 x2 1)
          2 -taylor                    ( 1-2 x2 x2)
         24 +taylor                    ( 1+4 x2 x4)
        720 -taylor                    ( 1-6 x2 x6)
      40320 +taylor                    ( 1+8 x2 x8)
    3628800 -taylor                    ( 1-10 x2 x10)
  479001600 +taylor                    ( 1+12 x2 x12)
  fdrop fdrop                          ( 1+12)
;

: ftan fdup fsin fswap fcos f/ ;       \ ftan = fsin / fcos

[DEFINED] 4TH# [IF]
hide >range
hide (taylor)
hide +taylor
hide -taylor
hide >taylor
[THEN]
[THEN]




 6 Posts in Topic:
Taylor series FSIN, FCOS, FTAN
"The Beez'" <  2008-04-26 04:12:45 
Re: Taylor series FSIN, FCOS, FTAN
Albert van der Horst <  2008-04-27 10:30:59 
Re: Taylor series FSIN, FCOS, FTAN
"The Beez'" <  2008-04-27 08:32:25 
Re: Taylor series FSIN, FCOS, FTAN
Albert van der Horst <  2008-04-27 17:04:51 
Re: Taylor series FSIN, FCOS, FTAN
"The Beez'" <  2008-04-27 08:45:45 
Re: Taylor series FSIN, FCOS, FTAN
"The Beez'" <  2008-04-28 02:33:38 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 2:02:36 CDT 2008.