POV-Ray : Newsgroups : povray.unofficial.patches : Bug in csqr? : Re: Bug in csqr? Server Time
2 Sep 2024 04:15:08 EDT (-0400)
  Re: Bug in csqr?  
From: david sharp
Date: 17 May 2000 10:30:56
Message: <3922ad20$1@news.povray.org>
Warp <war### [at] tagpovrayorg> wrote in message news:39229ca2@news.povray.org...
>   Try the following. Both printed lines should be identical (or at least
> almost identical). However, only the first one is the correct answer. The
> second one is buggy:
>
> $Z = <-.32, -1.97>;
> $Z2 = cmult(Z,Z);
> #debug concat("cmult(<",str(creal(Z),10,10),",",str(cimag(Z),10,10),">) =
")
> #debug concat("<",str(creal(Z2),10,10),",",str(cimag(Z2),10,10),">\n")
> $Z2 = csqr(Z);
> #debug concat(" csqr(<",str(creal(Z),10,10),",",str(cimag(Z),10,10),">) =
")
> #debug concat("<",str(creal(Z2),10,10),",",str(cimag(Z2),10,10),">\n")
>
>   In this Solaris 7 it outputs the following:
>
> cmult(<-0.3200000000,-1.9700000000>) = <-3.7785000000,1.2608000000>
>  csqr(<-0.3200000000,-1.9700000000>) = <-3.7785000000,14.8872900000>

Yes, csqr(Z) has a bug.
The source-level fix is to replace a line in express.c.


===== the bug ===========================
/*****************************************/
         case CSQR_TOKEN:
            #ifdef UnofficialBlocking
              parseUnofficialFeature(40);
            #endif
            Parse_Vector_Param(Vect);
/**** Replace the next line:*****/

Make_Vector(Vect,Vect[0]*Vect[0]-Vect[1]*Vect[1],2*Vect[0]*Vect[1],0.0);
/**********************/
            break;

===== a fix ========================

         case CSQR_TOKEN:
            #ifdef UnofficialBlocking
              parseUnofficialFeature(40);
            #endif
            Parse_Vector_Param(Vect);
/***** Replacement lines*********/
            cmplx2.x=Vect[0];cmplx2.y=Vect[1];

Make_Vector(Vect,cmplx2.x*cmplx2.x-cmplx2.y*cmplx2.y,2*cmplx2.x*cmplx2.y,0.0
);
/*****************************/
            break;


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.