[pltscheme] Numerical precision
From: Jaime Vargas (jev at mac.com)
Date: Thu Mar 12 12:11:04 EDT 2009 

I ended following Richard's advice and round only when calculating
interest. This a lot simpler that the parameterize solution and does
the job.
(define (makeround:p numericalprecision)
(define N (expt 10 numericalprecision))
(define 1/N (/ 1 N))
(lambda (x)
(* 1/N (round (* x N)))))
(define round:p (makeround:p 2))
Thanks for all the input,
 Jaime
On Mar 11, 2009, at 10:36 PM, Richard Cleis wrote:
> You want to do rounding or truncation according to the requirements
> of the simulation. He says that he is doing personal financial
> simulations, which implies to me that after each operation the
> simulation keeps only a certain precision (like a person would enter
> only n digits beyond the decimal in a spreadsheet, or write them
> from a calculator display.)
>
> Perhaps not :)
>
> rac
>
> On Mar 11, 2009, at 8:25 PM, Henk Boom wrote:
>
>> 2009/3/11 Richard Cleis <rcleis at mac.com>:
>>> You could consider computing everything with integers that
>>> represent the
>>> precision in your sim. (e.g., $1.23 would be 123 cents or 1230
>>> mills or
>>> whatever.) After a division or multiply, rounding or truncation
>>> can be used
>>> to create a new integer with the algorithm that your sim requires.
>>> Converting between the sim integers and $nn.nn needs to occur only
>>> when you
>>> want to display values or accept input.
>>
>> This does not avoid the associativity problems though, nor the
>> problems of accumulation of error. You really want to do rounding
>> only
>> when necessary.
>>
>> Henk
>> _________________________________________________
>> For listrelated administrative tasks:
>> http://list.cs.brown.edu/mailman/listinfo/pltscheme
>
> _________________________________________________
> For listrelated administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/pltscheme