From: pito <pi...@vo...> - 2010-09-23 17:57:37
|
..more compact, faster by 25%.P. \ fsin fcos ftan library \ amforth 4.0 \ Pito 23-9-2010 \ based on 4tH library by J.L. Bezemer \ needs Leon's flib (and Pito's asm flib v1.1 for speed) -fsincostan marker -fsincostan \ the original JLB (taylor) does not work, a bug? : >taylor fdup f* fover ; \ setup for Taylor series : _taylor fover f* frot fover ; : +taylor f/ f+ frot frot ; \ add Taylor iteration : -taylor f/ f- frot frot ; \ subtract Taylor iteration \ put x in RADIANS within 2pi range : >range $0FDB $4049 fdup f+ ( x pi2 ) fover fover f/ ( x pi2 x/pi2 ) ffloor fover f* ( x pi2 mod ) frot fswap f- ( pi2 mod ) $0FDB $4049 fover ( pi2 mod pi mod ) f< if fswap f- else fnip then ; \ calculate fcos : fcos 1 s>f fswap >range >taylor ( 1 x2 1 ) _taylor $0000 $4000 -taylor ( 1-2 x2 x2 ) _taylor $0000 $41C0 +taylor ( 1+4 x2 x4 ) _taylor $0000 $4434 -taylor ( 1-6 x2 x6 ) _taylor $8000 $471D +taylor ( 1+8 x2 x8 ) _taylor $7C00 $4A5D -taylor ( 1-10 x2 x10 ) _taylor $67E0 $4DE4 +taylor ( 1+12 x2 x12 ) \ _taylor $61D9 $51A2 +taylor ( 1-14 x2 x14 ) \ _taylor $3BBC $5598 +taylor ( 1+16 x2 x16 ) fdrop fdrop ; ( 1+12 ) \ calculate fsin : fsin $0FDB $3FC9 f- fcos ; \ calculate ftan : ftan fdup fsin fswap fcos f/ ; \ ftan = fsin / fcos |