Documentation
¶
Overview ¶
Package floats provides utilities for floating-point comparisons with epsilon tolerance to handle precision issues.
Usage ¶
if floats.Equal64(0.1+0.2, 0.3) {
// Handles floating-point precision issues
}
Index ¶
- Constants
- func Compare32(a, b float32, epsilon ...float32) int
- func Compare64(a, b float64, epsilon ...float64) int
- func Equal32(a, b float32, epsilon ...float32) bool
- func Equal64(a, b float64, epsilon ...float64) bool
- func IsZero32(a float32, epsilon ...float32) bool
- func IsZero64(a float64, epsilon ...float64) bool
Constants ¶
View Source
const Epsilon32 float32 = 1e-6
View Source
const Epsilon64 float64 = 1e-12
Default epsilon values for floating-point comparisons.
Variables ¶
This section is empty.
Functions ¶
func Compare32 ¶
Compare32 compares two float32 values with epsilon tolerance. Returns -1 if a < b, 0 if a == b (within epsilon), 1 if a > b.
func Compare64 ¶
Compare64 compares two float64 values with epsilon tolerance. Returns -1 if a < b, 0 if a == b (within epsilon), 1 if a > b. An optional custom epsilon can be provided.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.