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.

You Want to Visit the UK? You Better Have a Google Play or App Store Account

https://www.heltweg.org/posts/you-want-to-visit-the-uk-you-better-have-a-google-play-or-app-store...
57•rhazn•23m ago•39 comments

Show HN: Terminal Phone – E2EE Walkie Talkie from the Command Line

https://gitlab.com/here_forawhile/terminalphone
36•smalltorch•1h ago•13 comments

Google API keys weren't secrets, but then Gemini changed the rules

https://trufflesecurity.com/blog/google-api-keys-werent-secrets-but-then-gemini-changed-the-rules
751•hiisthisthingon•15h ago•150 comments

Show HN: Better Hub – A better GitHub experience

https://www.better-hub.com/
28•bekacru•1h ago•28 comments

Jimi Hendrix was a systems engineer

https://spectrum.ieee.org/jimi-hendrix-systems-engineer
521•tintinnabula•15h ago•164 comments

Tell HN: YC companies scrape GitHub activity, send spam emails to users

66•miki123211•2h ago•20 comments

How will OpenAI compete?

https://www.ben-evans.com/benedictevans/2026/2/19/how-will-openai-compete-nkg2x
272•iamskeole•13h ago•372 comments

Google API Keys Weren't Secrets. But Then Gemini Changed the Rules

https://simonwillison.net/2026/Feb/26/google-api-keys/
3•speckx•48m ago•1 comments

Banned in California

https://www.bannedincalifornia.org/
180•pie_flavor•12h ago•196 comments

First Website (1992)

https://info.cern.ch
235•shrikaranhanda•12h ago•64 comments

Making MCP cheaper via CLI

https://kanyilmaz.me/2026/02/23/cli-vs-mcp.html
238•thellimist•15h ago•98 comments

Windows 11 Notepad to support Markdown

https://blogs.windows.com/windows-insider/2026/01/21/notepad-and-paint-updates-begin-rolling-out-...
296•andreynering•18h ago•443 comments

Artist who “paints” portraits on glass by hitting it with a hammer

https://simonbergerart.com
181•cs702•3d ago•81 comments

Bus stop balancing is fast, cheap, and effective

https://worksinprogress.co/issue/the-united-states-needs-fewer-bus-stops/
371•surprisetalk•19h ago•534 comments

Out of Light Adjust Share: Caravaggio, La Tour, and the Art of Attention

https://harpers.org/archive/2026/03/out-of-light-nicole-krauss-caravaggio-georges-de-la-tour/
22•prismatic•3d ago•1 comments

Writers and Their Day Jobs

https://lithub.com/the-work-behind-the-writing-on-writers-and-their-day-jobs/
37•simplegeek•3d ago•11 comments

RAM now represents 35 percent of bill of materials for HP PCs

https://arstechnica.com/gadgets/2026/02/ram-now-represents-35-percent-of-bill-of-materials-for-hp...
284•jnord•9h ago•219 comments

Large-Scale Online Deanonymization with LLMs

https://simonlermen.substack.com/p/large-scale-online-deanonymization
279•DalasNoin•1d ago•203 comments

Show HN: Modern Reimplementation of the Speck Molecule Renderer

https://github.com/vangelov/modern-speck
4•vlad_angelov•4d ago•0 comments

Show HN: Respectify – A comment moderator that teaches people to argue better

https://respectify.org/
176•vintagedave•21h ago•160 comments

The First Fully General Computer Action Model

https://si.inc/posts/fdm1/
261•nee1r•2d ago•68 comments

A 26-Gram Butterfly-Inspired Robot Achieving Autonomous Tailless Flight

https://arxiv.org/abs/2602.06811
9•Terretta•3d ago•3 comments

Tech companies shouldn't be bullied into doing surveillance

https://www.eff.org/deeplinks/2026/02/tech-companies-shouldnt-be-bullied-doing-surveillance
296•pseudolus•11h ago•100 comments

The Om Programming Language

https://www.om-language.com/
270•tosh•18h ago•75 comments

Dissecting the CPU-memory relationship in garbage collection (OpenJDK 26)

https://norlinder.nu/posts/GC-Cost-CPU-vs-Memory/
96•jonasn•1d ago•26 comments

What Pressure Does to an Athlete's Body

https://www.theatlantic.com/culture/2026/02/pressure-olympics-malinin-shiffrin/686097/
37•bookofjoe•4d ago•8 comments

An autopsy of AI-generated 3D slop

https://aircada.com/blog/ai-vs-human-3d-ecommerce
76•sech8420•14h ago•45 comments

Gauss's Weekday Algorithm, Visualized

https://lukasmetzner.github.io/blog/gauss-weekday.html
41•lukasmetzner•4d ago•7 comments

GNU Texmacs

https://www.texmacs.org/tmweb/home/welcome.en.html
173•remywang•20h ago•48 comments

Learnings from 4 months of Image-Video VAE experiments

https://www.linum.ai/field-notes/vae-reconstruction-vs-generation
117•schopra909•1d ago•15 comments