floats

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2026 License: AGPL-3.0 Imports: 0 Imported by: 0

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

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

func Compare32(a, b float32, epsilon ...float32) int

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

func Compare64(a, b float64, epsilon ...float64) int

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.

func Equal32

func Equal32(a, b float32, epsilon ...float32) bool

Equal32 checks if two float32 values are equal within epsilon tolerance.

func Equal64

func Equal64(a, b float64, epsilon ...float64) bool

Equal64 checks if two float64 values are equal within epsilon tolerance.

func IsZero32

func IsZero32(a float32, epsilon ...float32) bool

IsZero32 checks if a float32 value is zero within epsilon tolerance.

func IsZero64

func IsZero64(a float64, epsilon ...float64) bool

IsZero64 checks if a float64 value is zero within epsilon tolerance.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL