Hipparchus-Math / hipparchus

An efficient, general-purpose mathematics components library in the Java programming language
Apache License 2.0
139 stars 41 forks source link

Add getAddendum() to CalculusFieldElement #349

Closed maisonobe closed 1 month ago

maisonobe commented 1 month ago

When we have some instance of CalculusFieldElement, we can extract its real part using getReal(). It should be possible to extract the remaining parts (i.e. everything not in getReal()), lets call it the addendum, by calling getAddendum().

With such a method, we would always have e.getAddendum().add(e.getReal()) be equal to the original e.

Note, however, that e.subtract(e.getReal()) does not always returns e.getAddendum(). One counter-example (which is in fact the one that is the rationale behind this issue) is when e.getReal() is ±∞. When this happens, the subtraction e.subtract(e.getReal()) implies subtracting one infinity to itself, and this generates a NaN for the real part, not zero.

As this changes an interface, and as due to the handling of infinities we cannot provide a default implementation based on simple subtraction, this change should be done in a major release.