Raising a negative number to a non-integer power will always result in a
complex number. I'm not sure why you're raising the signum to any power,
though; I think you want to return (* (signum base) *maxValue*).
--
Barry Margolin, bar...@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
I am not sure how to detect overflow, I'd probably try to prevent
it in the first place, but you can get rid of the complex numbers
easily by not computing -1^{2.3} or some such because that would
be exp(log (-1^2.3)) = exp(2.3 log(-1)) = exp(2.3 i pi).
Regards,
--
Nils Goesche
"Don't ask for whom the <CTRL-G> tolls."
PGP key ID 0x42B32FC9
[snip]
> (defun gexp (base power)
> "Secure exponential function: prevents floating point over- and
> underflows cau by large or small numbers of power and some bases near
> zero"
>
> (defun sub_gexp (base power)
> "Prevent over- and underflows"
Please note that defun defines a new function in the global environment
no matter where it occurs. When you want a local function, use flet
or labels instead.
Why not use a condition handler?
> In article <a75708$n8k$1...@tyfon.itea.ntnu.no>,
> Carsten Gester <pentyer...@gmx.net> wrote:
> > (defun sub_gexp (base power)
> > "Prevent over- and underflows"
> > (cond
> > ;; if power is a very large number (e.g 10E10) an overflow can occure
> > ((and (> power 0) (not (= base 0))
> > (> (log (abs base) *maxValue*) (/ 1 power)))
>
> Why not use a condition handler?
That was my first thought, too, but at least Lispworks doesn't
seem to throw the FLOATING-POINT-OVERFLOW condition but returns
an NaN instead. Do I have to enable it somehow first? Or should
I submit a bug report?
Regards,
--
Nils Goesche
Ask not for whom the <CONTROL-G> tolls.
PGP key ID 0xC66D6E6F