This site is updated infrequently. For up-to-date information, please visit the new OCaml website at ocaml.org.

What library to use for arbitrary precision decimals
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
 Date: 2006-02-19 (18:31) From: Brian Hurt Subject: Re: [Caml-list] What library to use for arbitrary precision decimals
```

On Sun, 19 Feb 2006, Jeremy Shute wrote:

> If you use the Int64 module as the basis for your computations, you can
> hold values up to \$184,467,440,737,095.51 in size.
>
> How many Vietnamese Dongs is that?  Some CIA factbook estimates of the GDP
> of the world:
>
> \$US 5.938e+13
>
> One dollar will buy you a lot of Vietnamese Dongs:
>
> \$VND 1.5838e+4

>
> So, the GDP of the world (a popular number, to be sure) is about:
>
> \$VND 9.4046e+17
>
> ...and the the max signed int64 is around...
>
> 9.2234e+18
>
> This is not an isolated case, there are quite a few currencies in the \$? 10K
> / \$US 1 range.  Point: you're one locale change and some depreciation away
> from overflowing when someone wants to calculate a ratio for analysis.  Why
> not use a big int?

You're right that if you're needing to calculate the World GDP, or even
the American debt, you may need more bits.  Although I was doing stuff in
millipennies, simply doing stuff in centipennies still leaves you enough
information to round to the nearest penny correctly, and gives you another
order of magnitude headroom.

The reason to use Int64 instead of Bigint is performance.  This may or may
not be an issue.  Although I note that both Bigint and Int64 performance
is going to way stomp BCD performance.

Brian

```