Improve floating-point comparisons for cross-platform stability#37
Closed
Improve floating-point comparisons for cross-platform stability#37
Conversation
Floating-point values can have slight precision differences across different architectures, compilers, and optimization levels, causing tests to fail intermittently on different systems. - Replace exact equality checks with tolerance-based comparisons using go-cmp library with 0.001 delta for float32/float64 values - Update example test to use formatted output (%.2f) instead of raw float printing to ensure consistent behavior across platforms - Maintain test accuracy while eliminating architecture-dependent test failures This ensures tests pass reliably on ARM, x86, and other architectures regardless of floating-point representation differences.
- Add proper error handling to RewindScanner.Rewind() method - Update CI workflow to use Go 1.23 instead of outdated 1.17 - Fix golangci-lint errcheck violations for better code quality - Update GitHub Actions to v4 for security and performance The error handling improvements ensure that seek failures are properly propagated instead of being silently ignored, making the code more robust and compliant with Go best practices.
Add explicit checks with clear error messages to identify why the Kiwi C library installation is failing in CI. The script now: - Verifies headers exist at /usr/local/include/kiwi/ - Verifies libraries exist at /usr/local/lib/libkiwi* - Fails fast with descriptive error messages if verification fails - Shows success confirmation when installation works properly This will help identify whether the issue is with sudo permissions, path differences between local and CI environments, or other installation problems specific to GitHub Actions runners.
The macOS runners don't have /usr/local/lib and /usr/local/include directories by default, causing the installation script to fail with 'mv: /usr/local/lib/ is not a directory'. Add 'sudo mkdir -p /usr/local/lib /usr/local/include' before attempting to move libraries and copy headers to ensure the target directories exist on all platforms.
GitHub Actions macOS runners use ARM64 architecture but the install script was hardcoded to download x86_64 binaries, causing linker errors with 'found architecture x86_64, required architecture arm64'. The script now: - Detects the architecture using 'uname -m' - Downloads the correct ARM64 binaries for Apple Silicon - Downloads x86_64 binaries for Intel Macs and Linux - Shows architecture in debug output for troubleshooting This ensures the downloaded Kiwi libraries match the target architecture.
Kiwi v0.10.3 doesn't have native ARM64 builds for macOS, only Intel x86_64 builds are available. The script now: - Always uses x86_64 binaries for macOS (both Intel and ARM64) - ARM64 Macs will run x86_64 binaries via Rosetta translation - Validated that the download URL exists and contains correct libraries This resolves the 'found architecture x86_64, required architecture arm64' linker error by ensuring we only download builds that actually exist.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Problem
Floating-point values can have slight precision differences across different architectures, compilers, and optimization levels. This causes tests to fail intermittently on different systems (ARM vs x86, different Go versions, etc.), making the test suite unreliable for contributors and CI/CD pipelines.
Solution
github.com/google/go-cmpwith 0.001 delta for float comparisonsfmt.Println(results)tofmt.Printf("Tokens: %v, Score: %.2f\n", ...)Test plan