Qalculate / libqalculate

Qalculate! library and CLI
https://qalculate.github.io/
GNU General Public License v2.0
1.88k stars 151 forks source link

Fix `Number.equals()` when allow_infinite = true #646

Closed afishhh closed 6 months ago

afishhh commented 6 months ago

Number.equals() would previously return different results depending on which value is this and which one is o when comparing an infinity with a finite value (when the internal rational is the same).

hanna-kn commented 6 months ago

The mistake meant that a.equals(b, ..., true) would return true if a is infinite and b is zero.

This directly affects MathStructure::equals(zero, ..., true), MathStructure::countOccurrences(zero) (infinite values counted), MathStructure::replace(zero, ...) (infinite values replaced), MathStructure::calculateReplace(zero, ...), and MathStructure::contains(zero, ..., ..., ..., true).

This will affect anyone who calls these functions directly in the library. I have however examined how they are used in within the library and any further significant consequences seem highly unlikely.