frontpage.
newsnewestaskshowjobs

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•1y ago

Comments

LegionMammal978•1y 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•1y 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•1y 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.

Play Store blocks AuroraStore, hurting GrapheneOS users

https://gitlab.com/AuroraOSS/AuroraStore/-/work_items/1566
250•erikvanoosten•2h ago•88 comments

What's new in Claude Fable 5.1

https://platform.claude.com/docs/en/models/fable-5-1/whats-new-fable-5-1
52•denysvitali•18m ago•16 comments

Launch HN: Nori Robotics (YC S26) – A low-cost humanoid robot for development

https://www.norirobotics.com/
27•AntonioLi•37m ago•3 comments

AnkiDroid: Google Play no longer allowing Open Collective donation link

https://github.com/ankidroid/Anki-Android/issues/21656
687•hexa555•8h ago•191 comments

Ambient CSS v3 – Blender meets CSS

https://ambientcss.vercel.app/
87•kikkupico•2h ago•36 comments

Ask HN: Who is hiring? (September 2026)

116•whoishiring•3h ago•116 comments

Fable 5.1 System Card

https://www.anthropic.com/document/claude-fable-5-1-mythos-5-1-system-card
11•alvis•4m ago•0 comments

Quill (YC W20) Is Hiring a Fullstack SWE

1•R_R•1h ago

I trained a small transformer in 1.5hrs and it beats many LLMs

https://mvakde.github.io/blog/44-on-arc-1/
362•porridgeraisin•8h ago•97 comments

Movie Scene Map – 13,312 films, series, games, anime and manga

https://moviescenemap.com/
26•Flightmussy•1h ago•12 comments

Claude Fable 5.1 and Claude Mythos 5.1

https://www.anthropic.com/claude-fable-and-mythos-5-1
57•meetpateltech•11m ago•6 comments

Io_uring Without Readahead

https://frn.sh/io-uring/
78•porridgeraisin•4h ago•20 comments

American Airlines mechanic Azriel “Al” Blackman has died, aged 100

https://simpleflying.com/american-airlines-mechanic-passes-away-100-record-80-years/
311•NaOH•2d ago•120 comments

The creator of Jujutsu has joined ERSC

https://ersc.io/blog/martin-joins-ersc
7•steveklabnik•26m ago•0 comments

Dr. Melvin Scheinman: 40th Anniversary of Catheter Ablation

https://ucsfhealthcardiology.ucsf.edu/facstaff/spotlight/dr-melvin-scheinman-40th-anniversary-cat...
31•efavdb•3d ago•4 comments

Thanks to Lake Ontario, MapQuest is popular all over again

https://www.washingtonpost.com/politics/2026/09/01/thanks-lake-ontario-mapquest-is-popular-all-ov...
70•reaperducer•1h ago•47 comments

Show HN: Running 104GB Qwen3.8-Flash-Next on 48GB Mac with at ~12 tok/s

https://github.com/carloslfu/slotstream
43•carloslfu•1h ago•41 comments

UEFA's Champions League draw creates unfair clusters; a Cayley graph fixes it

https://sariyuce.com/blog/2026/UEFA-Draw/
3•erdems•15m ago•0 comments

Physically Immutable Optical Archive Libraries

https://savartus.com/solutions/enterprise-laser-storage/
15•thunderbong•2d ago•7 comments

Fastpotify

https://fastpotify.rocks/
734•nreece•15h ago•470 comments

We are rebuilding Monica

https://www.monicahq.com/en/blog/we-are-rebuilding-monica/
63•robinhood•1d ago•41 comments

Keenable SELECT: an agent that searches the web in SQL

https://keenableai.github.io/select-showcase/
32•phoenix120•2h ago•7 comments

Dwarf Fortress' creator says the industry's in shambles over AI

https://www.pcgamer.com/gaming-industry/dwarf-fortress-creator-says-the-industrys-in-shambles-ove...
79•Limb•2h ago•54 comments

Introducing Ad Blocker for Firefox on iOS

https://blog.mozilla.org/en/firefox/ad-blocker-on-ios/
152•HieronymusBosch•4h ago•61 comments

Restroom Archive

https://restroomarchive.com
310•jcalx•14h ago•77 comments

A browser-based viewer for Office Open XML documents

https://ooxml.silurus.dev/
33•mathiaswp•2h ago•8 comments

Fractal Jittered Voronoi Partitions

https://www.boristhebrave.com/2026/08/29/fractal-jittered-voronoi-partitions/
60•jp3141•2d ago•6 comments

Tmp.0ut Volume 5

https://tmpout.sh/5/
168•ghuntley•18h ago•36 comments

Playa Phone

https://playaphone.com/
715•cutoff•1d ago•224 comments

I turned my security cameras into an automatic bird identification system

https://jasontucker.blog/how-i-turned-my-security-cameras-into-an-automatic-bird-identification-s...
590•speckx•1d ago•160 comments