-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
Description
Currently, svg seems to be buggy due to not adequately handling floating point arithmetic. I see three possible solutions:
1. Accommodate the precision limits of floating point arithmetic
E.g. instead of "if a = 1.5 you do if abs(a - 1.5) < limit". (Source.) This avoid bugs even if floating-point arithmetic has caused a to be, say, 1.49999999999999999999999999 instead of 1.5.
Pros:
- Calculations would remain fast.
- If CompSci students/graduates start working on the codebase, this approach would be familiar to them.
Cons:
- For non-CompScis (e.g. several current ContentMine contributors), floating point arithmetic violates the principle of least surprise, risking logic errors.
2. Use decimal arithmetic (e.g. BigDecimal) instead of floating point arithmetic (e.g. double)
Pros:
- Calculations would be more intuitive than floating point, for non-CompScis.
Cons:
- Slower than floating point arithmetic.
- Can't use normal arithmetic operators.
- Risks rounding errors.
3. Use arbitrary-precision arithmetic instead of floating point arithmetic
Pros:
- Obeys principle of least surprise, minimising risk of logic errors.
- According to (1, 2, 3) helpful sources, several suitable libraries exist:
| Library | Language | License |
|---|---|---|
| Apfloat | Java, C++ | LGPL |
| GMP | C and C++ w/Java bindings | LGPL |
| JAS | Java | LGPL |
| JLinAlg | Java | LGPL |
| JScience | Java | BSD-type |
Cons:
- Slower than floating point arithmetic.
- Requires a library dependency.
Reactions are currently unavailable