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.

SeL4 security proofs now complete on AArch64

https://proofcraft.systems/news-2026/#2026-08-21
59•snvzz•1h ago•14 comments

I were 17, I'd learn how to build LLMs from scratch

https://twitter.com/paulg/status/2091544343589060625
265•bilsbie•16h ago•380 comments

Everything I own, owned

https://schlarp.com/posts/everything-i-own-owned/
1108•schlarpc•14h ago•296 comments

Ask HN: Why do corporate failures always seem to punish the wrong people?

61•mittermayr•1h ago•32 comments

FDA clears blood test to aid evaluation for Alzheimer's disease

https://medicine.washu.edu/news/fda-clears-blood-test-to-aid-evaluation-for-alzheimers-disease/
91•dabinat•6h ago•29 comments

Executable Is a SQLite Database

https://fzakaria.com/2026/08/23/your-executable-is-a-sqlite-database
200•setheron•8h ago•27 comments

The Future Belongs to the Weird

https://essays.georgestrakhov.com/weird/
54•georgestrakhov•4h ago•27 comments

Anthropic's best AI model struggles to attract users as cheaper tools thrive

https://www.ft.com/content/5ee49718-c258-4f01-aa32-7e5b76ae5245
616•naves•19h ago•543 comments

How I find problems to solve as a staff engineer

https://lalitm.com/post/find-problems-staff-engineer/
458•vanpra•18h ago•136 comments

Fast drilldown dashboards from a single Parquet file

https://www.hamiltonulmer.com/customer-dashboards-r2-hyparquet/
62•v3gas•5h ago•1 comments

OCR It – pull text out of un-copyable documents for your LLM

https://github.com/thiagotigaz/ocr-it
74•thiagolima•7h ago•16 comments

Agent Is Not the Model

https://code.joejag.com/2026/your-agent-is-not-the-model.html
25•joejag•2h ago•3 comments

Andreessen Horowitz is investing billions into a bleak future

https://www.modelrepublic.org/articles/a16z-portfolio
334•reasonableklout•6h ago•116 comments

I built a low-latency AI companion that plays Skyrim with me

https://pantel.is/projects/ai-gaming-companion/
230•pantelisk•14h ago•42 comments

Why older tech is sometimes safer from hackers

https://www.bbc.com/future/article/20260821-why-older-tech-is-sometimes-safer-from-hackers
5•tchalla•2h ago•2 comments

Google Workspace thinks my domain is an email provider (2025)

https://blog.elis.cc/articles/google-workspace-thinks-my-domain-is-an-email-provider/
340•el1s7•17h ago•119 comments

Anthropic candidates face blunt money question

https://www.axios.com/2026/08/24/scoop-anthropic-candidates-face-blunt-money-question
23•samizdis•1h ago•29 comments

What Is a Harness?

https://earendil.com/posts/what-is-a-harness/
489•tosh•23h ago•157 comments

My agent.md to improve LLM-assisted code quality

https://fabiensanglard.net/agent.md/index.html
340•ibobev•19h ago•145 comments

Woman stranded in Spain after UK's eVisa system mistakes her for twin sister

https://www.theguardian.com/uk-news/2026/aug/24/woman-stranded-spain-uk-evisa-system-mistakes-twi...
93•giuliomagnifico•3h ago•72 comments

New EU-wide product repair rules come into force

https://www.rte.ie/news/business/2026/0824/1588931-repair-rules/
174•austinallegro•7h ago•105 comments

The treasury bond mess: is this the demise of the US as a safe haven?

https://www.theguardian.com/business/2026/aug/24/treasury-bonds-trump-administration-debt
60•fittingopposite•2h ago•35 comments

Mourning Steve French

https://lwn.net/Articles/1090098/
36•mfrw•8h ago•0 comments

How Complex Systems Fail (1998)

https://how.complexsystems.fail/
339•shortcrct•22h ago•72 comments

Malware infects Android-based automotive head unit firmware

https://securelist.com/android-head-unit-malware/121106/
251•campuscodi•1d ago•127 comments

AI Chip Architectures

https://www.jepeake.com/ai-chip-architectures
102•Finbarr•1d ago•36 comments

Fable and the end of the free lunch

https://www.dbreunig.com/2026/08/23/fable-the-end-of-moore-s-law.html
185•dbreunig•18h ago•170 comments

Over 5,200 Ebola cases recorded in Congo

https://www.afro.who.int/countries/democratic-republic-of-congo/news/over-5200-cases-recorded-dem...
85•simonebrunozzi•6h ago•35 comments

My favorite nonfiction books about cults, scams, and schemes

https://bookdna.com/best-books/nonfiction-about-cults-scams-and-schemes
252•bwb•23h ago•100 comments

Explain it to me like I'm ten

https://timharford.com/2026/08/explain-it-to-me-like-im-ten/
159•bookofjoe•19h ago•58 comments