Message78670
The decimal constructor should be lossless. The underlying spec was
designed with the notion that all numbers in decimal are exact;
operations can be lossy but the numbers themselves are exact.
Accordingly, I recommend Decimal.from_float(f) with no qualifiers or
optional arguments.
To support the use case of wanting to round the input, I suggest a
separate method modeled on Context.create_decimal(). It can either be
an extension of the existing method or a new method like
Context.create_decimal_from_float(). I recommend the former since
rounding is already implied by the context qualifier. Either way, the
effect would be the same as Decimal.from_float(f) + 0 in a given
context. Per the docs: "Creates a new Decimal instance from num but
using self as context. Unlike the Decimal constructor, the context
precision, rounding method, flags, and traps are applied to the conversion." |
|
Date |
User |
Action |
Args |
2009-01-01 00:38:25 | rhettinger | set | recipients:
+ rhettinger, steven.daprano |
2009-01-01 00:38:24 | rhettinger | set | messageid: <1230770304.9.0.829539552545.issue4796@psf.upfronthosting.co.za> |
2009-01-01 00:38:23 | rhettinger | link | issue4796 messages |
2009-01-01 00:38:20 | rhettinger | create | |
|