Chris Uppal said:
P.Hill said:
So
instead of just guffawing and falling out of my seat, I have to ask what
particular application area where you working in where you commonly
needed to count more than a long worth of fixed point such that you
wanted to even think of the idea of "aways using BigInteger"?
[...]
But more importantly, I don't want to have to /think/ about overflow at
all --
it's a distraction I don't need. I wouldn't advocate defaulting to using
Java
BigInteger/BigDecimal for numeric quantities myself, but that's mostly
because
of the incredible[*] awkwardness of expressing any kind of calculation
using
them.
Yeah, that's my main argument for "always use BigInteger" too: You no
longer have to worry about overflow at all.
Here's the one application I worked on where I got to try it out.
There's this dance game called In The Groove
(
http://www.inthegroove.com/), which is similar to the more widely known
Dance Dance Revolution. It has a few new features, including a USB slot on
the arcade machine itself which allows you to create an account and track
various statistics on your gameplay, including an estimate of how many
calories you've burned playing the game, how many times you played, what
your scores were for each song, etc.
This data is stored as XML files on the USB key, and is digitally signed
by the machine. I think the developers of the game are open source
advocates. They've released the schema for the XML files and a public key to
check the signature to allow third parties (like myself) to play around with
those files.
Now I assume that the code for the machine is implemented in C/C++, so
*probably* the machine itself doesn't support writing an XML file that says
the player played more than 2*10^19 games (which would probably actually
take 10^14 years to accomplish), but the schema file itself doesn't put any
restriction on the count. So rather than worrying about what internal limits
the machine uses (which might change from revision to revision; the machines
are currently at Version 2 Revision 8), I just store this count as a
BigInteger.
As I predicted, the bottleneck for my application (which is basically
just a specialized viewer for the XML file, rendering charts using jGraph
showing average calories burned per day, for example) was not integer
arithmatic, but rather file-IO. So by using BigInteger, I'd never have to
worry about any of the values from the XML ever causing an overflow error in
my application, and I didn't suffer significant performance loss.
- Oliver