[swift-evolution] Is there a need for a Decimal type?
rainer at brockerhoff.net
Mon Feb 15 10:37:16 CST 2016
On 2/15/16 13:58, Dave Abrahams via swift-evolution wrote:
> on Sat Feb 13 2016, Jonathan Tang <swift-evolution at swift.org> wrote:
>> General +1, but I'm wondering if a better development process would be to
>> release this as an open-source library, get some adoption, respond to
>> user-feedback, and then propose to integrate that library into the stdlib.
>> You can iterate much faster in a library than in the language standard, and
>> APIs usually end up being a lot cleaner when designed in response to user
>> feedback than when designed by committee. (Particularly when the library
>> in question is fairly domain-specific.)
> +1. That process is well-suited to *many* of the things people would
> like to see in the standard library.
Excellent comment, a Decimal type would be good to have at some point
down the road, if it's presented in the suggested way.
For whoever will try do write such a library, a few comments.
In a former life I had to write some financial packages (some of them in
Assembler, others in C) and there were no suitable libraries — this
because we had to consider hyperinflation — the local currency could at
times need over 15 significant digits just for values seen in the
The usual trick was to store values as big integers with implicit
decimal point 2 (or sometimes, 6) places to the left.
NSDecimal and NSDecimalNumber seem to use decimal floating point; that
gets around exact representation of 0.1 and similar values, but it could
suffer loss of significance just like binary floats would, so it might
not be a good idea to port them.
Rainer Brockerhoff <rainer at brockerhoff.net>
Belo Horizonte, Brazil
"In the affairs of others even fools are wise
In their own business even sages err."
More information about the swift-evolution