1. chk_pow_args() (to Andy)
- Posted by rolf.schroeder at desy.de Jun 14, 2002
- 462 views
Andy, Here a corrected version which accounts also for 0^b, b!=0. I forgot this case. But some more checks of this functions are recommended! Have a nice day, Rolf ------------------------------------------------------------------- constant lim = log(3e+307) -- needed for chk_pow_args() ------------------------------------------------------------------- function chk_pow_args(object a, object b) -- ------------ if atom(a) and atom(b) then if a > 0.0 then if b*log(a) < lim then return 1 end if elsif a < 0 then if integer(b) then if b*log(-a) < lim then return 1 end if else return 0 end if elsif b != 0.0 then -- case a=0 ! return 1 end if return 0 elsif length(a) = length(b) then for i = 1 to length(a) do if not chk_pow_args(a[i],b[i]) then return 0 end if end for end if return 0 end function ------------------------------------------------------------------- procedure test(atom a, atom b) -- ---- if chk_pow_args(a,b) then printf(1,"%24.15g%24.15g%24.15g\n",{a,b, power(a,b)}) else printf(1,"%24.15g%24.15g %s\n",{a,b,"power(a,b) failed!"}) -- puts(1,"power() failiour! Abort.\n") end if end procedure ------------------------------------------------------------------- test( 0.0950052, -300.784) test( 0.0950053, -300.784) test(-0.0950053, -300.784) test( 3.01 , -30.000) test(-3.01 , -30.000) test( 3.01 , -31.000) test(-3.01 , -31.000) test(-3.01 ,-9100.000) test(-3.01 ,-1e+9 ) test(-3.01 ,-1e+10 ) test( 3.01 ,-1e+9 ) test( 3.01 ,-1e+10 ) test( 1.01e+300, 1.01 ) test( 1.01e+300, -1.01 ) sequence s, t s = { 0.0950052, 0.0950052, -0.0950053} t = { -300.784 , -300.784 , -300.784 } ? s ? t ? chk_pow_args(s,t) s = { 0.0950052, 0.0950052, -0.0950052 , 1} t = { -300.784 , -300.784 , -300.784 } ? s ? t ? chk_pow_args(s,t) abort(0) -------------------------------------------------------------------