Re: power overflow

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hello Pete,

you wrote:

> <Snip>
> I just had:
>  if b>1 and log(a) > log(1e300)/b then it will overflow.

> Pete

I agree, but this condition is not sufficient if 'a' is negative.

If e.g.  a = -50, and b = 500, then power(a, b) will overflow, but
--------------------------------------------------------------
atom a, b
a = -50
b = 500
if b > 1 and log(abs(a)) > log(1e300)/b then
   puts(1, "overflow")
else
   ? power(a, b)
end if
--------------------------------------------------------------
will not print "overflow", but there will be an error with log().


So in my opinion, it should be something like this:
--------------------------------------------------------------
function abs (atom x)
   if x < 0 then x = -x end if
   return x
end function

atom a, b
a = -50
b = 500
if b > 1 and log(abs(a)) > log(1e300)/b then
   puts(1, "overflow")
else
   ? power(a, b)
end if
--------------------------------------------------------------


What I previously wrote, was (simplified):
--------------------------------------------------------------
if b > 1 and abs(a) > power(1e300, 1/b) then
   puts(1, "overflow")
else
   ? power(a, b)
end if
--------------------------------------------------------------

So you found the logarithm of my function.

Best regards,
   Juergen

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu