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.

Incremental – A library for incremental computations

https://github.com/janestreet/incremental
154•handfuloflight•4h ago•23 comments

Who's afraid of Chinese models?

https://stratechery.com/2026/whos-afraid-of-chinese-models/
591•mfiguiere•21h ago•399 comments

Running Doom on Our Custom CPU and Going Viral

https://www.armaangomes.com/blogs/doom/
53•arghunter•4h ago•10 comments

Kimi Work

https://www.kimi.com/products/kimi-work
520•ms7892•15h ago•225 comments

Jelly UI: Soft-body physics for native HTML form controls

https://jelly-ui.com/
459•baldvinmar•15h ago•150 comments

Five US tech giants' hidden debts soar to $1.65T on opaque AI funding

https://asia.nikkei.com/business/technology/five-us-tech-giants-hidden-debts-soar-to-1.65tn-on-op...
248•NordStreamYacht•4h ago•119 comments

Linux kernel will support $ORIGIN, sort of

https://fzakaria.com/2026/07/20/linux-kernel-will-support-origin-sort-of
18•ingve•1h ago•8 comments

Human mathematicians are being outcounterexampled

https://xenaproject.wordpress.com/2026/07/20/human-mathematicians-are-being-outcounterexampled/
323•artninja1988•13h ago•127 comments

A Koi Pond Mosaic Made from 10 Pounds of 3D Printer Waste

https://www.instructables.com/A-Koi-Pond-Mosaic-Made-From-10-Pounds-of-3D-Printe/
29•sudo_cowsay•4h ago•22 comments

Nativ: Run frontier open models locally on your Mac

https://blaizzy.github.io/nativ/
264•aratahikaru5•14h ago•87 comments

Flock Credibility Lost as It Repeatedly Lies to City Councils, Police, & Public

https://www.aclu.org/news/privacy-technology/tracking-alpr-cameras/flock-safety-credibility-lost-...
373•StatsAreFun•7h ago•103 comments

Show HN: Ex Situ – Open-source spatial index of displaced cultural artifacts

https://exsitu.app/map
26•hbyel•3h ago•13 comments

Show HN: Immersive Gaussian Splat tour of grace cathedral, San Francisco

https://vincentwoo.com/3d/grace_cathedral/
154•akanet•12h ago•33 comments

How to pack ternary numbers in 8-bit bytes

https://compilade.net/blog/ternary-packing
4•JoshTriplett•6d ago•1 comments

Agent swarms and the new model economics

https://cursor.com/blog/agent-swarm-model-economics
183•jlaneve•14h ago•83 comments

VTubing: How a Japanese Phenomenon Is Going Worldwide

https://www.tokyodev.com/articles/vtubing-how-a-japanese-phenomenon-is-going-worldwide
16•pwim•4h ago•1 comments

Launch HN: Bloomy (YC S26) – AI-powered mastery learning for K-12

85•alexsouthmayd•15h ago•86 comments

Tensor Notation in Mathup

https://mathup.xyz/#tensors
9•runarberg•6d ago•1 comments

China’s open-weights AI strategy is winning

https://werd.io/american-ai-is-locked-down-and-proprietary-its-losing/
1092•benwerd•17h ago•831 comments

The Psychology of Software Teams

https://www.routledge.com/The-Psychology-of-Software-Teams/Hicks/p/book/9781032963389
85•dcre•5d ago•22 comments

You only need the frontier model for one single edit

https://stencil.so/blog/prewalk
130•jxmorris12•6d ago•38 comments

The Power of Awareness: Overcoming Surveillance Capitalism

https://www.scottrlarson.com/presentations/overcoming-surveillance-capitalism-with-awareness/
101•trinsic2•12h ago•17 comments

My two year old taught me constraint solving

https://thecomputersciencebook.com/posts/how-my-2yo-taught-me-constraint-solving/
70•bambataa•1w ago•26 comments

Shinjuku Station in 3D

https://satoshi7190.github.io/Shinjuku-indoor-threejs-demo/
210•Gecko4072•18h ago•46 comments

I wrote an bash enumerator because I was sick of xargs

https://numerlab.org/2025/07/20/bashumerate-enumerator/
121•wallach-game•12h ago•101 comments

How we measured AI writing across arXiv, and where the measurement breaks

https://unslop.run/blog/measuring-ai-writing-on-arxiv
219•dopamine_daddy•15h ago•153 comments

Claude Fable produced a counterexample to the Jacobian Conjecture

https://xcancel.com/__alpoge__/status/2079028340955197566
746•loubbrad•1d ago•471 comments

Perfection is not over-engineering

https://var0.xyz/posts/perfection-is-not-over-engineering.html
235•var0xyz•18h ago•100 comments

Corners Don't Look Like That: Regarding Screenspace Ambient Occlusion (2012)

https://nothings.org/gamedev/ssao/
165•firephox•17h ago•70 comments

Hacker wipes Romania's land registry database

https://news.risky.biz/risky-bulletin-hacker-wipes-romanias-entire-land-registry-database/
637•speckx•18h ago•348 comments