[comp.lang.pascal] BUG IN MATH UNIT!!

wct@po.CWRU.Edu (William C. Thompson) (04/22/91)

For those of you that grabbed my "cool" math unit, a bug
was found in the pow function.  It has since been corrected
and fixed.  Here is the correct function:

function pow(a,b: real):real;
{ Computes a^b }
begin
  if a=0 then
    if b=0 then pow:=1                           { 0^0 = 1 }
    else if b<0 then pow:=exp(b*ln(a))           { force error }
    else pow:=0                                  { 0^x = 0 }
  else if a<0 then
    if abs(b)<1e-10 then pow:=1
    else if relerror(b,round(b))<1e-8 then
      pow:=(1-2*ord(odd(round(b))))*exp(b*ln(abs(a)))
    else if (relerror(1/b,round(1/b))<1e-8) and odd(round(1/b)) then
      pow:=-exp(b*ln(abs(a)))
    else pow:=exp(b*ln(a))                       { force error }
  else pow:=exp(b*ln(a))
end;

Oops!
-- 
Ticking away, the moments that make up a dull day.   | William C. Thompson
You fritter and waste the hours in an offhand way.   | Michelson 620D (wct)
Kicking around on a piece of ground in your hometown,| a.k.a. Master of Time,
waiting for someone or something to show you the way.| Space, and Dimension