[ANN] FixedPoint with selectable rounding

Chad Netzer cnetzer at mail.arc.nasa.gov
Wed Oct 9 19:05:36 EDT 2002


On Wednesday 09 October 2002 14:55, Piet van Oostrum wrote:
> >>>>> "dougfort" <dougfort at dougfort.net> (D) writes:

> D> You can select which rounding algorithm FixedPoint uses by assigning
> D> a bound function to FixedPoint.RoundingAlgorithm.
>
> The problem with such a more or less global assignment is that you can't
> use it in a thread-safe way.

Hmmm.  So, make it an initialization argument, with helpers to easily build 
FixedPoint's w/ whatever rounding you want.  If you want to change the 
rounding behavior, reconstruct (or call a setting method).

I'd consider going even further and using subclasses, as I would consider 
each rounding method a different type of FixedPoint, and could more easily 
check (or assert) that I have the one I care about, when it matters.   I'm 
assuming there are a small set of actually needed rounding methods, so the 
generality of setting your own function is not so important (one can always 
extend by subclassing on their own).

However, combining differing types of FixedPoints then becomes cumbersome...  
But, I might want it to be the case that I can't blithely combine types w/ 
different rounding behavior, without being more explicit.

Note - I haven't used the FixedPoint class, at all, so this is uninformed 
musing.

-- 

Chad Netzer
cnetzer at mail.arc.nasa.gov




More information about the Python-list mailing list