RE: Math crashes with translated programs (Rob?)

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

r.schr at t-online.de wrote:
> Andy Serpa wrote:
> > 
> > > I didn't get 0 with the interpreter! Correctly it reports:
> > >
> > >  tst.ex:5
> > >  math function overflow error
> > >  --> see ex.err
> > >
> > Really?  Maybe it is a processor thing.  Do you have an Intel?
> 
> No, it's an AMD K6-2 .
> 
That's what mine is -- with the interpreter, huh?  Well, I can't think 
of an explanation for that.  I use the PD interpreter -- is the complete 
edition any different in that regard?

> > ...
> > So I need a COMPLETE safe_power() function, it seems, that will protect
> > me from overflows from any possible atoms (integer or floating point,
> > positive or negative) used for base and exponent.  Anyone?
> >
> 
> I wouldn't use a "save_power()" function. Instead, I would check the two
> arguments before calling power(). May be the following function is
> useful for this purpose:
>  

Your function is exactly what I meant by safe_power(), and similar to 
one that was posted here just a few days ago.  

But the one I was using didn't catch something like (.02, -300.773)


> -------------------------------------------------------- 
> constant lim = log(3e+307)  -- needed for chk_pow_args()
> 
> function chk_pow_args(atom a, atom b)
> --       ------------
>     if a > 0.0 then
>         if b*log(a) < lim then
>             return 1
>         end if
>     elsif a < 0 and integer(a) then
>         if b*log(-a) < lim then
>             return 1
>         end if
>     end if
>     return 0
> end function
> 
> -- test:
> 
>     atom a, b
> 
>     a = 0.0951
>     b = -300.784
>     if chk_pow_args(a,b) then
>         ? power( a, b)
>     else
>         puts(1,"power() overflow! Abort.\n")
>     end if
> -------------------------------------------------------- 
> 
> Have a nice day, Rolf
> 
> 
>

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

Search



Quick Links

User menu

Not signed in.

Misc Menu