frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Comparing floating-point numbers (2012)

https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
26•sph•11mo ago

Comments

LegionMammal978•11mo ago
I'd argue that any equality comparison of floating-point numbers is asking for trouble, unless you're specifically working with small dyadic fractions (using exact comparison) or testing a purely heuristic 'closeness' condition (using fuzzy comparison).

Of course, inequalities show up in a lot more places, but are similarly fraught with difficulty, since mathematical statements may fail to translate to floating-point inequalities. E.g., in computational geometry, people have written entire papers about optimizing correct orientation predicates [0], since the naive method can easily break at small angles. This sort of thing is what often shows up as tiny seams in 3D video-game geometry.

[0] https://www.cs.cmu.edu/~quake/robust.html

mtklein•11mo ago
My preferred way to compare floats as being interchangeably equivalent in unit tests is

    bool equiv(float x, float y) {
        return (x <= y && y <= x)
            || (x != x && y != y);
    }
This handles things like ±0 and NaNs (while NaNs can't be IEEE-754-equal per se, they're almost always interchangeable), and convinces -Wfloat-equal you kinda know what you're doing. Also everything visually lines up real neat and tidy, which I find makes it easy to remember.

Outside unit tests... I haven't really encountered many places where float equality is actually what I want to test. It's usually some < or <= condition instead.

sph•11mo ago
I have built a production Javascript library with decent amounts of users that incorporates the following hack to deal with float error (avert your eyes if you're sensitive):

  // 1.2 - 1.0 === 0.19999999999999996
  // fixFloatError(1.2 - 1.0) === 0.2
  var fixFloatError = function (n) {
    return parseFloat(n.toPrecision(12));
  };
It felt correct at the time, but after reading the article, I cringe at how fundamentally broken it is. I got away with it because the library is used to convert betting odds, which are mostly small floating point numbers, so the error is often < 10^-12.

Any Color You Like: NIST Scientists Create 'Any Wavelength' Lasers

https://www.nist.gov/news-events/news/2026/04/any-color-you-nist-scientists-create-any-wavelength...
40•rbanffy•1h ago•7 comments

The electromechanical angle computer inside the B-52 bomber's star tracker

https://www.righto.com/2026/04/B-52-star-tracker-angle-computer.html
210•NelsonMinar•5h ago•65 comments

Thoughts and feelings around Claude Design

https://samhenri.gold/blog/20260418-claude-design/
137•cdrnsf•3h ago•88 comments

College instructor turns to typewriters to curb AI-written work

https://sentinelcolorado.com/uncategorized/a-college-instructor-turns-to-typewriters-to-curb-ai-w...
66•gnabgib•3h ago•49 comments

Optimizing Ruby Path Methods

https://byroot.github.io/ruby/performance/2026/04/18/faster-paths.html
17•weaksauce•1h ago•7 comments

Migrating from DigitalOcean to Hetzner

https://isayeter.com/posts/digitalocean-to-hetzner-migration/
624•yusufusta•8h ago•326 comments

State of Kdenlive

https://kdenlive.org/news/2026/state-2026/
306•f_r_d•10h ago•105 comments

Modern Common Lisp with FSET

https://fset.common-lisp.dev/Modern-CL/Top_html/index.html
34•larve•3d ago•0 comments

Michael Rabin has died

https://en.wikipedia.org/wiki/Michael_O._Rabin
365•tkhattra•3d ago•77 comments

Show HN: MDV – a Markdown superset for docs, dashboards, and slides with data

https://github.com/drasimwagan/mdv
71•drasim•6h ago•29 comments

Floating Point Fun on Cortex-M Processors

https://danielmangum.com/posts/floating-point-cortex-m/
21•hasheddan•1d ago•1 comments

Sumida Aquarium Posts 2026 Penguin Relationship Chart, with Drama and Breakups

https://www.sumida-aquarium.com/special/sokanzu/en/2026/
143•Lwrless•3d ago•5 comments

Traders placed over $1B in perfectly timed bets on the Iran war

https://www.theguardian.com/world/2026/apr/18/iran-war-bets-ethics-concerns
123•trocado•3h ago•86 comments

PgQue: Zero-Bloat Postgres Queue

https://github.com/NikolayS/pgque
48•gmcabrita•5h ago•3 comments

Opus 4.7 to 4.6 Inflation is ~45%

https://tokens.billchambers.me/leaderboard
372•anabranch•6h ago•388 comments

Show HN: AI Subroutines – Run automation scripts inside your browser tab

https://www.rtrvr.ai/blog/ai-subroutines-zero-token-deterministic-automation
16•arjunchint•1d ago•2 comments

UpCodes (YC S17) is hiring SDRs to help make construction more productive

https://up.codes/careers?utm_source=HN
1•Old_Thrashbarg•5h ago

Scientists discover "cleaner ants" that groom giant ants in Arizona desert

https://www.sciencedaily.com/releases/2026/04/260414075641.htm
63•t-3•3d ago•25 comments

Show HN: Remoroo. trying to fix memory in long-running coding agents

https://www.remoroo.com
20•adhamghazali•4d ago•3 comments

Graphs that explain the state of AI in 2026

https://spectrum.ieee.org/state-of-ai-index-2026
55•bryanrasmussen•5h ago•36 comments

4-bit floating point FP4

https://www.johndcook.com/blog/2026/04/17/fp4/
26•chmaynard•4h ago•14 comments

80386 Memory Pipeline

https://nand2mario.github.io/posts/2026/80386_memory_pipeline/
71•wicket•4d ago•10 comments

Amiga Graphics Archive

https://amiga.lychesis.net/
222•sph•16h ago•63 comments

Fuzix OS

https://www.fuzix.org/
65•DeathArrow•6h ago•24 comments

Understanding the FFT Algorithm (2013)

https://jakevdp.github.io/blog/2013/08/28/understanding-the-fft/
39•peter_d_sherman•3d ago•3 comments

Category Theory Illustrated – Orders

https://abuseofnotation.github.io/category-theory-illustrated/04_order/
217•boris_m•15h ago•57 comments

It's OK to compare floating-points for equality

https://lisyarus.github.io/blog/posts/its-ok-to-compare-floating-points-for-equality.html
164•coinfused•4d ago•112 comments

Show HN: I made a calculator that works over disjoint sets of intervals

https://victorpoughon.github.io/interval-calculator/
284•fouronnes3•21h ago•49 comments

Why Japan has such good railways

https://worksinprogress.co/issue/why-japan-has-such-good-railways/
263•RickJWagner•9h ago•264 comments

Towards trust in Emacs

https://eshelyaron.com/posts/2026-04-15-towards-trust-in-emacs.html
174•eshelyaron•3d ago•26 comments