4 ms·
Arbitrary precision rationals increase in storage and processing time each time you multiply them, so they open you up to DoS attacks. My order of preference:
by MichaelBurge 10y ago
Arbitrary precision rationals increase in storage and processing time each time you multiply them, so they open you up to DoS attacks.
My order of preference:
* Fixed-point arithmetic: All-around safe, though you'll probably need to take a maintenance window later if you need extra precision.
* Floating point arithmetic: Sounds dangerous, but you can eliminate most of the risk using database checks.
* Arbitrary-precision arithmetic: Almost any place they're used opens you up to DoS attacks; it's very difficult to detect the problem. I'd ensure my database and application server have debugging symbols installed, replace libgmp with something that alerts by generating core dumps when a timing threshold is passed, use a language where backtraces are easy to read in gdb, and ensure that all arbitrary-precision arithmetic is written against gmp. I'm not sure what I'd do when I detected the problem though: If I truncated 1 + 1/(10^10)! to 1 to resolve the issue, it's equivalent to using floating point in the first place.
- SolarNet 10y ago> Arbitrary precision rationals increase in storage and processing time each time you multiply them Only if you store the arbitrary precision number. Last I checked you can't actually have a tenth of a cent, so it has to be rounded at some point. Like when you store it. I was advocating calculation be done with arbitrary precision numbers which do not have this problem. > Fixed-point arithmetic This is a decent solution as long as you have enough precision and a strategy for detecting lost cents. > Floating point arithmetic Which is non-deterministic based off of optimization level and hardware. Waits for the bank to switch to a new cluster and watch all of their numbers change for the lols. No wonder banks don't know how much money they have.