|
|
Up |
|
|
  |
Author: The Beez'The Beez' Date: Apr 26, 2008 04:12
Thanks for your replies! I've come up with these ones, based on the
Taylor series. It requires a separate FP stack and can't be used for
large values as well, (which function should I use, Albert, to reduce
this one?), but it is rather simple and relatively accurate.
Hans Bezemer
[UNDEFINED] fsin [IF]
[UNDEFINED] floats [IF]
include lib/ansfloat.4th
[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
|
| Show full article (1.71Kb) |
|
| | 5 Comments |
|
  |
Author: Albert van der HorstAlbert van der Horst Date: Apr 27, 2008 03:30
>Thanks for your replies! I've come up with these ones, based on the
>Taylor series. It requires a separate FP stack and can't be used for
>large values as well, (which function should I use, Albert, to reduce
>this one?), but it is rather simple and relatively accurate.
For large values you should do range reduction. It amount to
subtraction multiples of 2*pi and such. At least try to land
in the [-PI, PI] interval.
It is wise to at least take that from the sources I supplied. This
greatly affects precision. If you omit range reduction, with your
Taylor series, it still works in principle.
For Chebychev it breaks down.
in the
>
>Hans Bezemer
>
>[UNDEFINED] fsin [IF]
>[UNDEFINED] floats [IF]
>include lib/ansfloat.4th
>[THEN]
>
>: f-rot frot frot ; \ inverted frot
>: >taylor fdup f* fover ; ...
|
| Show full article (2.62Kb) |
|
| | no comments |
|
  |
Author: The Beez'The Beez' Date: Apr 27, 2008 08:32
On Apr 27, 12:30 pm, Albert van der Horst
wrote:
> For large values you should do range reduction. It amount to
> subtraction multiples of 2*pi and such. At least try to land
> in the [-PI, PI] interval.
> It is wise to at least take that from the sources I supplied. This
> greatly affects precision. If you omit range reduction, with your
> Taylor series, it still works in principle.
> For Chebychev it breaks down.
: REDUCE.2PI \ x
PI*2 \ x pi2
FOVER FOVER F/ \ x pi2 x/pi2
FLOOR \ x pi2 i(x/pi2)
FOVER F* \ x pi2 mod(x,pi2)
FROT \ PI2 MOD(X,PI2) X
FSWAP F- \ PI2 MOD(X,PI2)
FOVER 2E F/ FOVER \ PI2 MOD PI MOD
F< IF FSWAP F- ELSE FNIP THEN ;
|
| Show full article (1.11Kb) |
| no comments |
|
  |
Author: The Beez'The Beez' Date: Apr 27, 2008 08:45
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
;
|
| Show full article (1.78Kb) |
| no comments |
|
  |
Author: Albert van der HorstAlbert van der Horst Date: Apr 27, 2008 10:04
In article d1g2000hsg.googlegroups.com>,
The Beez' bigfoot.com> wrote:
>On Apr 27, 12:30 pm, Albert van der Horst
>wrote:
>> For large values you should do range reduction. It amount to
>> subtraction multiples of 2*pi and such. At least try to land
>> in the [-PI, PI] interval.
>> It is wise to at least take that from the sources I supplied. This
>> greatly affects precision. If you omit range reduction, with your
>> Taylor series, it still works in principle.
>> For Chebychev it breaks down.
>
>: REDUCE.2PI \ x
> PI*2 \ x pi2
> FOVER FOVER F/ \ x pi2 x/pi2
> FLOOR \ x pi2 i(x/pi2)
> FOVER F* \ x pi2 mod(x,pi2)
> FROT \ PI2 MOD(X,PI2) X
> FSWAP F- \ PI2 MOD(X,PI2)
> FOVER 2E F/ FOVER \ PI2 MOD PI MOD ...
|
| Show full article (1.67Kb) |
| no comments |
|
  |
|
|
  |
Author: The Beez'The Beez' Date: Apr 28, 2008 02:33
On 27 apr, 19:04, Albert van der Horst
wrote:
> This is ugly shorthand for 2.0e0. That IS a float.
> If the reduced number is greater than pi , another 2pi is
> subtracted. You get pi by dividing by 2 (which need not
> be an efficient thing to do in your situation).
I think it was the comment that triggered me, but it suddenly came to
me. I was confused by the "FOVER 2e0 F/" sequence, since in most
situations you rather insert the constant again than to calculate it.
First I thought of "2E" as a hexadecimal number, but that made no
sense in any context. I came pretty close to your word by myself, but
I couldn't get the PI adjustment just right. Now it works.
Many thanks, Albert! Now I can release 4tH with a pretty nice FP
wordset, including FSIN, FCOS and FTAN. I hope nobody will use it
outside a government environment ;-)
Hans
|
| |
| no comments |
|
RELATED THREADS |
  |
|
|
|