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•9mo ago

Comments

LegionMammal978•9mo 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•9mo 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•9mo 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.

Nobody Gets Promoted for Simplicity

https://terriblesoftware.org/2026/03/03/nobody-gets-promoted-for-simplicity/
330•aamederen•3h ago•189 comments

Glaze by Raycast

https://www.glazeapp.com/
91•romac•2h ago•48 comments

"It Turns Out"

https://jsomers.net/blog/it-turns-out
29•Munksgaard•41m ago•8 comments

Motorola GrapheneOS devices will be bootloader unlockable/relockable

https://grapheneos.social/@GrapheneOS/116160393783585567
1010•pabs3•14h ago•409 comments

Qwen3.5 Fine-Tuning Guide – Unsloth Documentation

https://unsloth.ai/docs/models/qwen3.5/fine-tune
68•bilsbie•3h ago•14 comments

The one science reform we can all agree on, but we're too cowardly to do

https://www.experimental-history.com/p/the-one-science-reform-we-can-all
19•sito42•40m ago•2 comments

Apple Introduces MacBook Neo

https://www.apple.com/newsroom/2026/03/say-hello-to-macbook-neo/
291•dm•1h ago•288 comments

Chimpanzees Are into Crystals

https://www.nytimes.com/2026/03/04/science/chimpanzees-crystals.html
42•jimnotgym•7h ago•20 comments

Libre Solar – Open Hardware for Renewable Energy

https://libre.solar
32•evolve2k•3d ago•8 comments

RFC 9849. TLS Encrypted Client Hello

https://www.rfc-editor.org/rfc/rfc9849.html
182•P_qRs•8h ago•79 comments

RE#: how we built the fastest regex engine in F#

https://iev.ee/blog/resharp-how-we-built-the-fastest-regex-in-fsharp/
116•exceptione•3d ago•45 comments

Greg Knauss Is Losing Himself

https://shapeof.com/archives/2026/2/greg_knauss_is_losing_himself.html
28•wallflower•2d ago•3 comments

Jiga (YC W21) Is Hiring

https://jiga.io/about-us
1•grmmph•3h ago

Charging a three-cell nickel-based battery pack with a Li-Ion charger [pdf]

https://www.ti.com/lit/an/slyt468/slyt468.pdf
13•theblazehen•1d ago•0 comments

Elevator Saga: The elevator programming game (2015)

https://play.elevatorsaga.com/index.html
55•xmprt•3d ago•8 comments

Agentic Engineering Patterns

https://simonwillison.net/guides/agentic-engineering-patterns/
323•r4um•10h ago•174 comments

A CPU that runs entirely on GPU

https://github.com/robertcprice/nCPU
169•cypres•11h ago•85 comments

Bet on German Train Delays

https://bahn.bet
217•indiantinker•5h ago•146 comments

Better JIT for Postgres

https://github.com/vladich/pg_jitter
113•vladich•9h ago•42 comments

Show HN: Stacked Game of Life

https://stacked-game-of-life.koenvangilst.nl/
103•vnglst•3d ago•21 comments

Medical journal says the case reports it has published for 25 years are fiction

https://retractionwatch.com/2026/03/03/canadian-pediatric-society-journal-correction-case-reports...
14•Tomte•32m ago•0 comments

Modern Illustration: Archive of illustration from c.1950-1975

https://www.modernillustration.org
33•eustoria•3d ago•4 comments

Apple Announces Low-Cost 'MacBook Neo' with A18 Pro Chip

https://www.macrumors.com/2026/03/04/apple-announces-low-cost-macbook-neo-with-a18-pro-chip/
46•vanburen•1h ago•12 comments

Claude's Cycles [pdf]

https://www-cs-faculty.stanford.edu/~knuth/papers/claude-cycles.pdf
709•fs123•1d ago•299 comments

A Visual Guide to DNA Sequencing

https://www.asimov.press/p/dna-sequencing
5•surprisetalk•1h ago•0 comments

Graphics Programming Resources

https://develop--gpvm-website.netlify.app/resources/
152•abetusk•13h ago•13 comments

Did Alibaba just kneecap its powerful Qwen AI team?

https://venturebeat.com/technology/did-alibaba-just-kneecap-its-powerful-qwen-ai-team-key-figures...
63•GTP•2h ago•20 comments

Show HN: I made a zero-copy coroutine tracer to find my scheduler's lost wakeups

https://github.com/lixiasky-back/coroTracer
38•lixiasky•1d ago•1 comments

Weave – A language aware merge algorithm based on entities

https://github.com/Ataraxy-Labs/weave
161•rs545837•13h ago•91 comments

Voxile: A ray-traced game made in its own engine and programming language

https://elbowgreasegames.substack.com/p/voxray-games-pushes-major-update
247•spacemarine1•18h ago•65 comments