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

Comments

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

Internet Archive Switzerland

https://internetarchive.ch/
316•hggh•5h ago•44 comments

PipeDream on the Acorn Archimedes

https://stonetools.ghost.io/pipedream-archimedes/
44•msephton•2h ago•13 comments

The Intolerable Hypocrisy of Cyberlibertarianism

https://matduggan.com/the-intolerable-hypocrisy-of-cyberlibertarianism/
99•ColinWright•3h ago•51 comments

LLMs Corrupt Your Documents When You Delegate

https://arxiv.org/abs/2604.15597
203•rbanffy•8h ago•67 comments

Google broke reCAPTCHA for de-googled Android users

https://reclaimthenet.org/google-broke-recaptcha-for-de-googled-android-users
1335•anonymousiam•22h ago•486 comments

Using Claude Code: The unreasonable effectiveness of HTML

https://twitter.com/trq212/status/2052809885763747935
334•pretext•12h ago•207 comments

How LEDs are made (2014)

https://learn.sparkfun.com/tutorials/how-leds-are-made/all
84•smig0•2d ago•11 comments

A recent experience with ChatGPT 5.5 Pro

https://gowers.wordpress.com/2026/05/08/a-recent-experience-with-chatgpt-5-5-pro/
512•_alternator_•14h ago•368 comments

Mythical Man Month

https://martinfowler.com/bliki/MythicalManMonth.html
284•ingve•2d ago•173 comments

America's carpet capital: an empire and its toxic legacy

https://apnews.com/projects/pfas-forever-stained/
125•rawgabbit•3d ago•69 comments

OpenAI’s WebRTC problem

https://moq.dev/blog/webrtc-is-the-problem/
416•atgctg•2d ago•129 comments

Introduction to Beaver Triples

https://stoffelmpc.com/stoffel-blog/beaver-triples-tuples
6•badcryptobitch•1h ago•1 comments

GrapheneOS fixes Android VPN leak Google refused to patch

https://cyberinsider.com/grapheneos-fixes-android-vpn-leak-google-refused-to-patch/
110•Georgelemental•3h ago•27 comments

Building the TD4 4-Bit CPU

https://jayakody2000lk.blogspot.com/2026/05/building-td4-4-bit-cpu.html
32•zdw•2d ago•10 comments

Making Julia as Fast as C++ (2019)

https://flow.byu.edu/posts/julia-c++
61•d_tr•2d ago•43 comments

Reviving the IBM Selectric Composer Fonts (2023)

https://www.kutilek.de/selectric/
46•tangus•2d ago•5 comments

David Attenborough's 100th Birthday

https://www.bbc.com/news/articles/cp3pww9g0p5o
783•defrost•1d ago•152 comments

What causes lightning? The answer keeps getting more interesting

https://www.quantamagazine.org/what-causes-lightning-the-answer-keeps-getting-more-interesting-20...
143•Tomte•3d ago•37 comments

Show HN: Mochi.js: bun-native high-fidelity browser automation library

https://mochijs.com/
10•ccheshirecat•3h ago•3 comments

Killswitch: Per-function short-circuit mitigation primitive

https://lwn.net/ml/all/20260507070547.2268452-1-sashal@kernel.org/
61•signa11•8h ago•13 comments

Show HN: Free tool to mark points and polygon regions

https://tack.pics
15•magikMaker•2d ago•3 comments

Wi is Fi: Understanding Wi-Fi 4/5/6/6E/7/8 (802.11 n/AC/ax/be/bn)

https://www.wiisfi.com/
319•homebrewer•3d ago•88 comments

Removing fsync from our local storage engine

https://fractalbits.com/blog/remove-fsync/
51•zzsheng•2d ago•40 comments

Read Programming as Theory Building

https://codeutopia.net/blog/2026/05/09/you-should-read-programming-as-theory-building/
65•birdculture•4h ago•11 comments

AI is breaking two vulnerability cultures

https://www.jefftk.com/p/ai-is-breaking-two-vulnerability-cultures
386•speckx•23h ago•155 comments

Cartoon Network Flash Games

https://www.webdesignmuseum.org/flash-game-exhibitions/cartoon-network-flash-games
391•willmeyers•1d ago•120 comments

An Introduction to Meshtastic

https://meshtastic.org/docs/introduction/
480•ColinWright•1d ago•176 comments

The context window has been shattered: Subquadratic debuts a 12M token window

https://thenewstack.io/subquadratic-12-million-context-window/
28•gmays•2h ago•5 comments

The React2Shell Story

https://lachlan.nz/blog/the-react2shell-story/
196•mufeedvh•1d ago•40 comments

AWS North Virginia data center outage – resolved

https://www.cnbc.com/2026/05/08/aws-outage-data-center-fanduel-coinbase.html
250•christhecaribou•1d ago•179 comments