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

BYOMesh – New LoRa mesh radio offers 100x the bandwidth

https://partyon.xyz/@nullagent/116499715071759135
138•nullagent•3h ago•43 comments

Why TUIs Are Back

https://wiki.alcidesfonseca.com/blog/why-tuis-are-back/
149•rickcarlino•2h ago•129 comments

Southwest Headquarters Tour

https://katherinemichel.github.io/blog/travel/southwest-headquarters-tour-2026.html
133•KatiMichel•4h ago•23 comments

Statue of a man blinded by a flag put up by Banksy in central London

https://www.smithsonianmag.com/smart-news/attributed-to-banksy-a-new-statue-of-a-suited-man-blind...
113•dryadin•2h ago•66 comments

OpenAI's o1 correctly diagnosed 67% of ER patients vs. 50-55% by triage doctors

https://www.theguardian.com/technology/2026/apr/30/ai-outperforms-doctors-in-harvard-trial-of-eme...
143•donsupreme•20h ago•88 comments

US–Indian space mission maps extreme subsidence in Mexico City

https://phys.org/news/2026-04-usindian-space-mission-extreme-subsidence.html
35•leopoldj•2d ago•10 comments

A desktop made for one

https://isene.org/2026/05/Audience-of-One.html
146•xngbuilds•5h ago•55 comments

Bad Connection: Global telecom exploitation by covert surveillance actors

https://citizenlab.ca/research/uncovering-global-telecom-exploitation-by-covert-surveillance-actors/
62•miohtama•4h ago•4 comments

Mercedes-Benz commits to bringing back physical buttons

https://www.drive.com.au/news/mercedes-benz-commits-to-bringing-back-phycial-buttons/
505•teleforce•6h ago•299 comments

Show HN: Ableton Live MCP

https://github.com/bschoepke/ableton-live-mcp
35•bschoepke•3h ago•15 comments

Security through obscurity is not bad

https://mobeigi.com/blog/security/security-through-obscurity-is-not-bad/
85•mobeigi•6h ago•89 comments

Text-to-CAD

https://github.com/earthtojake/text-to-cad
39•softservo•2d ago•12 comments

Lost in translation: The linguistic challenges facing N. Korean defectors (2025)

https://www.dailynk.com/english/lost-in-translation-the-linguistic-challenges-facing-n-korean-def...
12•spzb•2d ago•2 comments

How far behind is each major Chromium browser?

https://chromium-drift.pages.dev/
137•skaul•4h ago•53 comments

I recreated the Apple Lisa computer inside an FPGA [video]

https://www.youtube.com/watch?v=8jNQDcpHc68
42•cyrc•3h ago•5 comments

Make Your Own Microforest

https://ambrook.com/offrange/environment/a-forest-in-your-pocket
17•bookofjoe•1h ago•0 comments

I built my own hair electrolysis machine

https://www.scd31.com/posts/diy-hair-electrolysis-machine
116•y1n0•4d ago•20 comments

Metal Gear Solid 2's source code has been leaked on 4chan

https://www.thegamer.com/mgs2-hd-edition-source-code-massive-leak/
162•rishabhd•4h ago•58 comments

Alert-driven monitoring

https://simpleobservability.com/docs/alert-driven-monitoring
86•khazit•7h ago•36 comments

What is Z-Angle Memory and why is Intel developing it?

https://www.hpcwire.com/2026/02/05/what-is-z-angle-memory-and-why-is-intel-developing-it/
66•rbanffy•2d ago•25 comments

Talking to Transformers

https://miraos.org/blog/2026/05/02/talking-to-transformers
14•taylorsatula•2h ago•2 comments

Nuclear receptor 4A1 linked to health effects of coffee: study

https://sciencex.com/news/2026-04-coffee-doesnt-key-biological-pathway.html
94•pseudolus•9h ago•70 comments

Underwater robot tracks sperm whale conversations in real time

https://www.reuters.com/business/environment/underwater-robot-tracks-sperm-whale-conversations-re...
22•thedebuglife•4h ago•1 comments

Modern jet engine turbines: each blade a single crystal (2015)

https://www.americanscientist.org/article/each-blade-a-single-crystal
32•whycome•7h ago•6 comments

Denuvo has been cracked in all single-player games it previously protected

https://www.tomshardware.com/video-games/pc-gaming/denuvo-has-been-bypassed-in-all-single-player-...
164•oceansky•5d ago•61 comments

Brain scans reveal 3 ADHD subtypes

https://www.washingtonpost.com/health/2026/04/30/adhd-subtype-extreme-brain-scans/
71•brandonb•2d ago•52 comments

Cordouan Lighthouse

https://en.wikipedia.org/wiki/Cordouan_Lighthouse
25•Petiver•4d ago•3 comments

Infrasound waves stop kitchen fires, but can they replace sprinklers?

https://arstechnica.com/gadgets/2026/05/startup-says-sound-waves-can-replace-fire-sprinklers-expe...
37•0in•1d ago•22 comments

Show HN: Apple's SHARP running in the browser via ONNX runtime web

https://github.com/bring-shrubbery/ml-sharp-web
143•bring-shrubbery•11h ago•36 comments

A couple million lines of Haskell: Production engineering at Mercury

https://blog.haskell.org/a-couple-million-lines-of-haskell/
395•unignorant•21h ago•196 comments