Fixed numbers (Was: Builtin Float Epsilon? )

Mike Meyer mwm at mired.org
Sun Feb 23 18:14:27 CET 2003


Carlos Ribeiro <cribeiro at mail.inet.com.br> writes:
[Requirements for a fixed number type in Python.]
> Unfortunately, any proposal that meet all requirements will need some special 
> syntax - and that's really HARD to do, because it will surely get a lot of 
> resistance, with good reason.

A good start would be a fixed number type. It should include a new
type "fixed" that accepts a string and an optional precision. I.e.:

fixed("3.1416") - 3.1416, with four decimal places
fixed("1", 3) - 1.000, with three decimal places

Doing this in C would make it easier to get it included in the
language. Doing it in Python allows you to experiment with some of the
semantics and find the problem areas.

> 2.1. Represent fixed point numbers using some modifier in the same way it is 
> already done with strings (raw and unicode modifiers, for example). Some 
> possibilites are:
> 
>    -->  3.1416f4 represents the number 3.1416, with precision 4
>    -->  1f4         represents the number 1.000, with precision 4

I like this one. It shouldn't break existing programs, and is a
natural extension of the existing "1e2" notation.

> There are some exceptional situations to handle:
> 
>    --> 1.02f1     
>      option a) round to 1.0 with precision 1
>      option b) raise an exception
>      [I sincerely don't know which one is better]

You missed an option:

        c) round to 1.0 and issue a warning.

I like that one.

        <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.




More information about the Python-list mailing list