Developer finds cross-platform float bug while porting JavaScript color library to Rust
A developer porting TinyColor, a 15-year-old JavaScript color library, to Rust discovered a subtle floating-point discrepancy when running the original test suite unmodified via WebAssembly. Forty-four of forty-five tests passed immediately, but the final test revealed a one-unit-in-the-last-place difference in a WCAG contrast ratio calculation between native and browser builds. The root cause was traced to how Rust's standard library computes the sRGB linearization function using pow, which produced slightly different results across compilation targets. The fix replaced the pow-based calculation with a precomputed lookup table of exact 64-bit float bit patterns for all 256 possible input values. The incident highlighted that strict exact-float assertions, often considered bad practice, can catch silent cross-platform inconsistencies that epsilon-based comparisons would miss entirely.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in