| Georgi Guninski on Mon, 10 Aug 2026 14:49:41 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Some numerical instability suggested by the Gemini AI |
I don't claim this is a bug, just FYI. Suggested by Gemini, prompts by me, based on floating point instability. Follows session: ? pre = 38; ? default(realprecision, pre); ? ? 0.1 + 0.2 == 0.3 %4 = 0 ? b = default(realbitprecision); ? x = 2.0^b; ? x==x+1 %7 = 1 ? x==x+2 %8 = 0 Attach is more serious floating point numbers in python.
#gemini python code about floats
import math
# 1. Non-Associativity: (a + b) + c != a + (b + c)
a, b, c = 1e16, -1e16, 1.0
(a + b) + c # 1.0
a + (b + c) # 0.0
(a + b) + c == a + (b + c) # False
# 2. Binary Decimal Inexactness
0.1 + 0.2 # 0.30000000000000004
0.1 + 0.2 == 0.3 # False
# 3. The Absorption Wall (53-bit mantissa limit in float64)
x = 2.0**53 # 9007199254740992.0
x + 1.0 # 9007199254740992.0
x + 1.0 == x # True
x + 2.0 == x # False
# 4. NaN Breaks Reflexivity and Trichotomy
nan = float("nan")
nan == nan # False
nan != nan # True
nan < 1.0 # False
nan >= 1.0 # False
# 5. Signed Zero Equivalence vs. Behavior
pos_zero, neg_zero = 0.0, -0.0
pos_zero == neg_zero # True
math.copysign(1.0, pos_zero) # 1.0
math.copysign(1.0, neg_zero) # -1.0
# 6. Indeterminate Forms
inf = float("inf")
inf - inf # nan
inf * 0.0 # nan
# 7. The Container 'in' Operator Trap (identity 'is' vs equality '==')
nan_a = float("nan")
nan_b = float("nan")
nan_a in [nan_a] # True (checks identity 'is' first)
nan_a in [nan_b] # False (falls back to '==', which evaluates to False!)