Kristian Nielsen wrote:
> Jim Starkey <[email protected]> writes:
>
>> But as I have mentioned before, dropping into arbitrary precision
>> binary to handle currency is really foolish. A 64 bit int can hold a
>> lot of dollars and cents and is a hell of a lot faster than arbitrary
>
> Yes, 64-bit ints holding centi-cents sounds quite good for currency, 18 digits
> of precision (19 for insigned).
>
> (And a $200 CPU can do 30 billion 64-bit additions/subtractions per second.)
>
> I once attended a talk from someone who developed a system that handles
> pension funds for every person in Sweden. Their problem was with the
> application language (which was Perl), which does not have any native 64-bit
> integer (they ended up working with some bignum package).
>
> Now that I think it over, I do not remeber seeing a 64-bit integer type in any
> high-level application language. Perl does not have it, Javascript does not. I
> think Java used to not have it, maybe it's been included in Java/.NET by
> now. I don't think PHP has it either, not sure about PHP/Python?
Python has 64-bit integers:
>>> x=2**64
>>> x
18446744073709551616L
Python actually has arbitrary length integers:
>>> x=2**255
>>> x
57896044618658097711785492504343953926634992332820282019728792003956564819968L
It auto-upgrades you to a "long" object if the number exceeds the limits
of a "normal int. I believe that in Python 3.0 they're doing away with
the plain int and all numbers will be the above "long" type.
> It's common for application/scripting languages to use IEEE doubles for
> numbers. But they have only 14 digits of precision, and that was just below
> the requirements for the Swedish pension system at least (I don't really
> remember, but it was something like needing 6 places after the decimal point,
> and magnitudes up to 1 billion before, which translates to 15 digits).
For floating point, python's stuff is float:
>>> x=2**255/1.0
>>> x
5.7896044618658098e+76
In python, if any of the elements of the expression are float, the
result gets turned into a float.
For decimal stuff, you can use the decimal package:
>>> import decimal
>>> x=decimal.Decimal(2**255)
>>> x
Decimal("57896044618658097711785492504343953926634992332820282019728792003956564819968")
www2.hursley.ibm.com/decimal/decarith.html
www.cs.berkeley.edu/~ejr/projects/754/private/drafts/854-1987/dir.html
are the standards implemented by the decimal module. "Decimal floating
point has finite precision with arbitrarily large bounds."
If you want more than that - there is NumPy and also python bindings to GMP.
Monty
_______________________________________________
Mailing list: https://launchpad.net/~drizzle-discuss
Post to : [email protected]
Unsubscribe : https://launchpad.net/~drizzle-discuss
More help : https://help.launchpad.net/ListHelp