Skip to content

Instantly share code, notes, and snippets.

@cloudhan
Created January 10, 2025 09:35
Show Gist options
  • Save cloudhan/6d95bc65b4f477e6bf96be50ab10abba to your computer and use it in GitHub Desktop.
Save cloudhan/6d95bc65b4f477e6bf96be50ab10abba to your computer and use it in GitHub Desktop.
Demonstration of IEEE 754 floating point non-associative
import numpy as np
a = np.array(3/7, dtype=np.float32)
b = np.array(713/999, dtype=np.float32)
c = np.array(7/11, dtype=np.float32)
print("{:30.26f}\n{:30.26f}".format((a + b) + c, a + (b + c)))
# 1.77864873409271240234375000
# 1.77864885330200195312500000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment