On Numbers
Terry Hancock
hancock at anansispaceworks.com
Mon Jan 16 10:59:10 EST 2006
On 15 Jan 2006 21:14:33 -0800
"Dan Bishop" <danb_83 at yahoo.com> wrote:
> although I personally would prefer
>
> (number)
> / \
> (realnumber) complex
> | | |
> int float |
> |
> Decimal
Mathematically, "real numbers" are a subset of "complex
numbers", though, so the set hierarchy would look like this:
"number"
|
complex
|
"real"
|
"rational"
|
+-----,
| |
float decimal
| |
+-----'
|
int
Noting of course that "real" and "number" are only
abstract concepts -- they can't truly be represented
on the computer. AFAIK, there is no general purpose
"rational" type in Python, but there could be.
I'm bothered by the fact that "int" can be coerced into
either "decimal" or "float". In practice, you should
have to choose one or the other. Practically speaking,
it probably makes more sense to do this:
"number"
|
complex
|
"real"
|
float
|
decimal
|
int
Because, in general, it is safer (no info loss) to
convert "int" to "decimal" where possible.
OTOH, for scientific or other performance-critical
applications, the exactitude of 'decimal' is less
desireable than the known precision and higher speed
of float implementations.
I suspect this is the sort of decision that was viewed
as "too tricky".
--
Terry Hancock (hancock at AnansiSpaceworks.com)
Anansi Spaceworks http://www.AnansiSpaceworks.com
More information about the Python-list
mailing list