Skip to content

Refactor floating point comparisons to use epsilon-based functions for improved precision#28

Open
tinboxw wants to merge 1 commit into
tidwall:masterfrom
tinboxw:master
Open

Refactor floating point comparisons to use epsilon-based functions for improved precision#28
tinboxw wants to merge 1 commit into
tidwall:masterfrom
tinboxw:master

Conversation

@tinboxw

@tinboxw tinboxw commented Aug 23, 2025

Copy link
Copy Markdown

In the amd64 and arm64 platform architectures, there may be inconsistencies in floating-point comparison calculations. As shown in the following figure, it is the debugging result of the IntersectsSegment function. I took the same input and output different results under different architectures.
I used the epsilon method to solve this problem.

arm64:
480b837ba206238eedded83c425da7cb

amd64:
f5701788553fb1df35e7081adc72e337

@tidwall

tidwall commented Jan 6, 2026

Copy link
Copy Markdown
Owner

Can you please provide the inputs and varying platform details?

@rickb777

Copy link
Copy Markdown

This seems like a good PR to me.

I suggest making some of the functions into methods: specifically

  • func PointEqual(a, b Point) bool could be func (a Point) Equal(b Point) bool
  • func RectEqual(a, b Rect) bool could be func (a Rect) Equal(b Rect) bool

and then the PointNotEqual, RectNotEqual functions are not required.

This would slim down the API footprint, which would be easier for users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants