Re: power overflow
- Posted by jluethje at gmx.de Jun 02, 2002
- 431 views
Ooops, I forgot to mention the 3rd function. >> 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 The 3rd function in this context is: a = power(y, 1/b) . This means, a_max = power(y_max, 1/b) -------------------------- a_max = power(+1e300, 1/b) -------------------------- When b = 576 (as in your example above), a cannot be more than a_max = power(+1e300, 1/576) = 3.32 . So you can see, that a = 24 is much too big. Checking the calculation gives: y = power(3.32, 576) = 1.498084165e+300 That's OK, and we see, that +1e300 is only *roughly* the biggest number, that Euphoria can handle. Best regards, Juergen