[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Programming - Using Floating Point Variables



PureBytes Links

Trading Reference Links

I have been programming scientific applications since 1960!

I should know better when it comes to a compiler that only uses
Floating Point variables.

I quite often use a parameter with a decimal fraction to represent
two items such as:  xx.y

Where xx    is extracted as one input parameter and
       y*10 is extracted as a second parameter.

The following is what I had coded for a current application.


ModeSum=IntPortion(SumMode);
If ModeSum<1 then ModeSum=ModeSum+8;
UseSum=FracPortion(SumMode)*10;
If UseSum>0 then begin
   Value1=IntPortion((UseSum+1)/2)*2;
   TypeSum=UseSum-Value1;    {-1=Low 0=high}
   GrpDiv=IntPortion(Value1/2)+1;
   If ModeSum<5 then ModeSum=ModeSum+4;
End;


I chased problems for two days with the following logic -- it
just did not do as it was seemingly supposed to.  I printed
out the values and they looked good on the "message log" (which
uses 2 decimal places).  Still did not work.


If Value11 >= ToDayJu  OR  ModeSum>4  then DoPlot=1;
				
If UseSum>0 then begin
   DoPlot=Iff(TypeSum=-1 and K>(M-1)  ,0,DoPlot);
   DoPlot=Iff(TypeSum= 0 and K<(KNT-1),0,DoPlot);
End;


Then I changed the code to the following -- notice the rounding
and integering I did.  Probably did more than was necessary but
it worked.



ModeSum=IntPortion(SumMode+.01);
If ModeSum<1 then ModeSum=ModeSum+8;
UseSum=IntPortion(FracPortion(SumMode+.01)*10);
If UseSum>0 then begin
   Value1=IntPortion((UseSum+1.1)/2)*2;
   TypeSum=UseSum-Value1;  {-1=Low 0=high}
   GrpDiv=IntPortion(Value1/2)+1;
   If ModeSum<5 then ModeSum=ModeSum+4;
End;


Moral of this story -- be very, very, very careful when 
performing logical comparison on Floating Point (in EL THAT
IS ALL YOU HAVE) variables.

Kick my butt again and again.

Clyde Lee



-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Clyde Lee   Chairman/CEO       (Home of SwingMachine)
SYTECH Corporation             email:   <clydelee@xxxxxxx> 
7910 Westglen, Suite 105       Work:    (713) 783-9540
Houston,  TX  77063            Fax:     (713) 783-1092    
SM available at:               ftp://intrepid.com/pub/clyde 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -