Skip to content

Choose floating point arithmetic, decimal arithmetic, or arbitrary precision arithmetic #2

@ghost

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:

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:

3. Use arbitrary-precision arithmetic instead of floating point arithmetic

Pros:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions