Re: power overflow

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

Hello tone,

you wrote:

> I get this error message:

> C:\MyProj\Euphoria\TSLibrary\TSLibrary_Formula_Finder.e:232 in function
> power_()
> math function overflow error
>     a = 24
>     b = 576


> where power (a,b) is executed

> How can I check parameters a and b and not execute power() if they are too
> big (especially b)?
> I guess one way is to write my own version of power()?


This is a snippet from my private file math.e:

------------------------------------------------------------------------
global function ln (object x)
-- Euphoria's built-in log() function
-- (= logarithm for base e = natural logarithm)

   return log(x)
end function


without warning
global function log (atom b, object x)
-- general log() function
-- logarithm for base b and number (or sequence) x
-- Note: built-in routine log() redefined

-- in : b: positive real number, != 1
--      x: positive real number (or sequence of those numbers)
-- out: real number
--      (x = 1  -->  function returns 0 for any base b)

   return ln(x)/ln(b)
end function
with warning
------------------------------------------------------------------------

Given this general log() function,

y = power(a, b) is equivalent to

b = log(a, y) .

When we know the maximum numeric value, that Euphoria can handle
(y_max), then we have:

b_max = log(a, y_max) .

After refman_2.htm, y_max = +1e300, i.e.

-------------------------
b_max = log(a, +1e300)
-------------------------

When a = 24 (as in your example above), b cannot be more than

b_max = log(24, +1e300) = 217.36 .

So you can see, that b = 576 is much too big.


Now we check the calculation:

y = power(24, 217.36) = 1.006272255e+300

OK smile

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