[Info-vax] New VSI Roadmap (yipee!)

David Froble davef at tsoft-inc.com
Sun Mar 1 00:13:47 EST 2015


John Reagan wrote:
> On Friday, February 27, 2015 at 6:37:14 PM UTC-5, David Froble wrote:
> 
>> We have a subprogram to round a D-float number:
>>
>> Call NRound( Z , 2% )
>>
>> The second parameter is the number of fraction decimal places.
>>
>> Every time it's called, there is subprogram frame set-up and break-down, 
>> and it has proven to be significant.  I'm aware that we can compile in a 
>> manner to suppress that overhead.  Regardless, Bill's request is for a 
>> built in rounding function.  Something like:
>>
>> Z = FRound( Z , 2% )
>>
>> I'm not sure what this would mean for anything other than D-Float ..
>>
>> How would you handle that, rounding for all the available floating point 
>> types?  Different function names for each?
> 

> Rounding floating point to certain number of decimal places?  That
> doesn't make sense.  Floating numbers are exact.  1.23 isn't really
> 1.23 but something close to it.  I don't know what a float-to-float
> rounding does?

Don't yell at me!  I'm aware that world + dog says don't use FP for 
currency.  Well, we do.

When doing FP operations, with currency amounts, each operation can 
cause small drift to occur, and sometimes after enough operations, you 
can be off a half penny.

So after each operation, we round the value to 2 decimal places, getting 
rid of any potential drift.

100     !************************************************************
         !                    Round a Real Number
         !************************************************************
         !
         SUB NROUND ( Z , Z% )
         !
         !  Z            - Real value
         !  Z%           - Digits to right of decimal point
         !
         !************************************************************
         !
         OPTION SIZE=( INTEGER WORD , REAL DOUBLE )

200     Z0 = FIX( ABS(Z) * 10.^Z% + .500001 )           !  SCALE TO AN 
INTEGER
         Z = ( Z0 / 10.^Z% ) * SGN(Z)                    !  RESCALE, SET 
SIGN
                                                         !
999     SUBEND

Ok, it's simple, but calling it many times is a performance issue.

There can be many reasons to round a FP number to a specified number of 
digits after the DP.



More information about the Info-vax mailing list