Message78784
One also has to worry about the exponent of the converted result: e.g.,
should Decimal.from_float(10.0) produce Decimal('1E1') or Decimal('10')?
The latter looks nicer, to me.
IEEE 754 isn't much help here: as far as I can tell it says nothing about
binary <-> decimal conversions.
I see two reasonable strategies: (1) always use the largest exponent
possible (so we'd get Decimal('1E1') above), or (2) when the quantity
converted is an exact integer, use an exponent of zero; otherwise fall
back to (1).
Option (2) is pretty much what the recipe in the docs does already, I
think: it computes a quotient of two Decimals, each having exponent zero,
so the preferred exponent of the result is also zero. |
|
Date |
User |
Action |
Args |
2009-01-02 11:48:37 | mark.dickinson | set | recipients:
+ mark.dickinson, rhettinger, steven.daprano |
2009-01-02 11:48:37 | mark.dickinson | set | messageid: <1230896917.76.0.887409781686.issue4796@psf.upfronthosting.co.za> |
2009-01-02 11:48:37 | mark.dickinson | link | issue4796 messages |
2009-01-02 11:48:36 | mark.dickinson | create | |
|