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.

Previewing GPT‑5.6 Sol: a next-generation model

https://openai.com/index/previewing-gpt-5-6-sol/
777•minimaxir•7h ago•478 comments

A C++ implementation of a fast hash map and hash set using hopscotch hashing

https://github.com/Tessil/hopscotch-map
50•gjvc•2h ago•6 comments

US allows Anthropic to release Mythos to 'trusted partners'

https://www.reuters.com/technology/us-releases-anthropic-model-mythos-some-us-companies-semafor-r...
119•bobrenjc93•1h ago•57 comments

U.S. government will decide who gets to use GPT-5.6

https://www.washingtonpost.com/technology/2026/06/26/openai-says-us-government-will-vet-users-its...
748•alain94040•5h ago•863 comments

The gap between open weights LLMs and closed source LLMs

https://blog.doubleword.ai/frontier-os-llm
91•kkm•2h ago•75 comments

Why does kinetic energy increase quadratically, not linearly, with speed? (2011)

https://physics.stackexchange.com/questions/535/why-does-kinetic-energy-increase-quadratically-no...
15•ProxyTracer•1h ago•0 comments

MicroVMs: Run isolated sandboxes with full lifecycle control

https://aws.amazon.com/blogs/aws/run-isolated-sandboxes-with-full-lifecycle-control-aws-lambda-in...
239•justincormack•3d ago•138 comments

We can still stop California's 3D printer surveillance scheme

https://www.eff.org/deeplinks/2026/06/we-can-still-stop-californias-3d-printer-surveillance-scheme
147•hn_acker•2h ago•26 comments

A Tiny Compiler for Data-Parallel Kernels

https://healeycodes.com/a-tiny-compiler-for-data-parallel-kernels
12•healeycodes•1d ago•0 comments

The "Bizarre Headgear" exhibit at the Sam Noble museum

https://svpow.com/2026/05/15/the-bizarre-headgear-exhibit-at-the-sam-noble-museum-is-incredible/
65•surprisetalk•3d ago•6 comments

Show HN: Smart model routing directly in Claude, Codex and Cursor

https://github.com/workweave/router
135•adchurch•7h ago•86 comments

Hightouch (YC S19) Is Hiring

https://hightouch.com/careers#open-positions
1•joshwget•3h ago

AI in mathematics is forcing big questions

https://spectrum.ieee.org/ai-in-mathematics
11•rbanffy•1h ago•5 comments

Ultrasound imaging of the brain

https://alephneuro.com/blog/ultrasound-brain
223•rossant•12h ago•92 comments

What Is a Nomogram and Why Would It Interest Me?

https://lefakkomies.github.io/pynomo-doc/introduction/introduction.html#what-is-a-nomogram-and-wh...
72•Eridanus2•6h ago•14 comments

The open source DOCX editor submitted to HN a few weeks ago has been deleted

38•gcanyon•2h ago•30 comments

PlayStation Is Deleting 551 Movies from Customers' Accounts

https://kotaku.com/playstation-store-movies-digital-studio-canal-terminator-2000711013
126•ortusdux•4h ago•72 comments

A human postmortem of the 1996 AOL outage

https://ngrok.com/blog/aol-was-down-1996
30•EndEntire•2d ago•6 comments

Gossamer: a Rust-flavoured language with real goroutines and pause-free memory

https://gossamer-lang.org/
63•mwheeler•5h ago•50 comments

Long Wave radio era set to end with Droitwich switch-off

https://www.bbc.com/news/articles/c74yn7v7k4qo
39•speckx•4h ago•17 comments

Show HN: Autofit2 – End-to-end pipeline for multilingual text classification

https://github.com/neospe/autofit2
12•leschak•1d ago•1 comments

Lippmann Photography

https://www.jonhilty.com/lippmann
11•andsoitis•2d ago•0 comments

Pre-Modern Armies for Worldbuilders, Part III: Paying for It

https://acoup.blog/2026/06/26/collections-pre-modern-armies-for-worldbuilders-part-iii-paying-for...
35•jfoucher•6h ago•3 comments

Modern GPU Programming for MLSys

https://mlc.ai/modern-gpu-programming-for-mlsys/
55•crowwork•3d ago•9 comments

The Art of Kite Flying (1430–1929)

https://publicdomainreview.org/collection/art-of-kite-flying/
22•benbreen•4d ago•10 comments

LaTeX.wasm: LaTeX Engines in Browsers

https://www.swiftlatex.com/
79•theanonymousone•3d ago•29 comments

Data centers trigger voter backlash

https://www.newsweek.com/cost-me-the-election-data-centers-trigger-voter-backlash-12118327
152•randycupertino•6h ago•270 comments

My Steam Machine is a 50ft HDMI cable

https://blog.matthewbrunelle.com/my-steam-machine-is-a-50ft-hdmi-cable/
155•speckx•3d ago•152 comments

Slisp: Simple Lisp compiler (Linux/amd64)

https://github.com/skx/slisp
52•stevekemp•5h ago•2 comments

Bipartite Matching Is in NC

https://scottaaronson.blog/?p=9851
107•amichail•4d ago•16 comments