Sujet : Re: Differentiable Forth
De : melahi_ahmed (at) *nospam* yahoo.fr (ahmed)
Groupes : comp.lang.forthDate : 26. Jul 2024, 13:27:06
Autres entêtes
Organisation : novaBBS
Message-ID : <f892e753c0d657d592749d9d80632328@www.novabbs.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14
User-Agent : Rocksolid Light
There is another problem with dl^.
The definition of dl^ given previously has problems:
a b dl^ doesn't work when:
- a is a dual number with negative real part ( for example: a =
-5.6 + eps c, c in R)
and (in the same time)
- b is a dual number with real part is integer and even ( for
example: b = 8 + eps d, d in R)
For floats, we have -5.6e 8e f** f. 967173.11574016 ok
But with dl^, we get : -5.6e f>dl 8e f>dl dl^ dl. NaN+ eps NaN ok
Here is the new definition of dl^, it corrects this problem.
: is_even_integer? ( f: a --) ( -- f)
fdup f>s dup s>f f=
swap 2 mod 0= and
;
: dl^ ( dl: a b -- a^b) \ a^b = exp(b*ln(a))
dldup dl>rl f0= if dldrop dldrop 1e 0e exit then
dldup dl>rl is_even_integer? if
dlswap
fswap fabs fswap
dlln dl* dlexp exit
then
dlover dl>rl f0<> if dlswap dlln dl* dlexp exit then
dldrop dldrop 0e 0e
;
For the same example, it gives
-5.6e f>dl 8e f>dl dl^ dl. 967173.11574016 + eps 0.
which is ok.
Ahmed