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

Comments

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

Go hard on agents, not on your filesystem

https://jai.scs.stanford.edu/
275•mazieres•7h ago•149 comments

AMD's Ryzen 9 9950X3D2 Dual Edition crams 208MB of cache into a single chip

https://arstechnica.com/gadgets/2026/03/amds-ryzen-9-9950x3d2-dual-edition-crams-208mb-of-cache-i...
124•zdw•5h ago•61 comments

Make macOS consistently bad unironically

https://lr0.org/blog/p/macos/
381•speckx•12h ago•260 comments

.apks are just .zips; semi-legally hacking software for orphaned hardware [video]

https://www.youtube.com/watch?v=P1kfuCkWo24
34•abadar•2d ago•9 comments

The bee that everyone wants to save

https://naturalist.bearblog.dev/the-bee-that-everyone-wants-to-save/
67•nivethan•2d ago•14 comments

LG's new 1Hz display is the secret behind a new laptop's battery life

https://www.pcworld.com/article/3096432/lgs-new-1hz-display-is-the-secret-behind-a-new-laptops-ba...
209•robotnikman•4d ago•99 comments

Trust Signals as Sparklines for Hacker News

https://hn-trustspark.com/
9•solaire_oa•1d ago•1 comments

Anatomy of the .claude/ folder

https://blog.dailydoseofds.com/p/anatomy-of-the-claude-folder
467•freedomben•17h ago•212 comments

Nashville library launches Memory Lab for digitizing home movies

https://www.axios.com/local/nashville/2026/03/16/nashville-library-digitize-home-movies
143•toomuchtodo•4d ago•33 comments

Velxio 2.0 – Emulate Arduino, ESP32, and Raspberry Pi 3 in the Browser

https://github.com/davidmonterocrespo24/velxio
136•dmcrespo•11h ago•42 comments

Show HN: Twitch Roulette – Find live streamers who need views the most

https://twitchroulette.net/
101•ellg•9h ago•50 comments

ISBN Visualization

https://annas-archive.gd/isbn-visualization?
148•Cider9986•11h ago•23 comments

‘Energy independence feels practical’: Europeans building mini solar farms

https://www.euronews.com/2026/03/26/suddenly-energy-independence-feels-practical-europeans-are-bu...
269•vrganj•22h ago•252 comments

Improving Composer through real-time RL

https://cursor.com/blog/real-time-rl-for-composer
78•ingve•1d ago•20 comments

Installing a Let's Encrypt TLS certificate on a Brother printer with Certbot

https://owltec.ca/Other/Installing+a+Let%27s+Encrypt+TLS+certificate+on+a+Brother+printer+automat...
211•8organicbits•18h ago•52 comments

Meow.camera

https://meow.camera/#4258783365322591678
244•surprisetalk•17h ago•58 comments

Iran-linked hackers breach FBI director's personal email

https://www.reuters.com/world/us/iran-linked-hackers-claim-breach-of-fbi-directors-personal-email...
226•m-hodges•17h ago•332 comments

The Future of SCIP

https://sourcegraph.com/blog/the-future-of-scip
66•jdorfman•16h ago•21 comments

Telnyx package compromised on PyPI

https://telnyx.com/resources/telnyx-python-sdk-supply-chain-security-notice-march-2026
98•ramimac•22h ago•101 comments

Explore the Hidden World of Sand

https://magnifiedsand.com/
225•RAAx707•4d ago•38 comments

Arm releases first in-house chip, with Meta as debut customer

https://www.cnbc.com/2026/03/24/arm-launches-its-own-cpu-with-meta-as-first-customer.html
4•goplayoutside•3d ago•1 comments

Fets and Crosses: Tic-Tac-Toe built from 2458 discrete transistors

https://schilk.co/projects/fetsncrosses/
40•voxadam•3d ago•11 comments

People inside Microsoft are fighting to drop mandatory Microsoft Account

https://www.windowscentral.com/microsoft/windows-11/people-inside-microsoft-are-fighting-to-drop-...
616•breve•17h ago•453 comments

Building FireStriker: Making Civic Tech Free

https://firestriker.org/blog/building-firestriker-why-im-making-civic-tech-free
116•noleary•1d ago•26 comments

Embracing Bayesian methods in clinical trials

https://jamanetwork.com/journals/jama/fullarticle/2847011
99•nextos•4d ago•11 comments

Colorado House passes bill to limit surveillance pricing and wage setting

https://coloradonewsline.com/briefs/surveillance-pricing-wage-setting/
99•jprs•11h ago•25 comments

Desk for people who work at home with a cat

https://soranews24.com/2026/03/27/japan-now-has-a-special-desk-for-people-who-work-at-home-with-a...
391•zdw•16h ago•139 comments

Capability-Based Security for Redox: Namespace and CWD as Capabilities

https://www.redox-os.org/news/nlnet-cap-nsmgr-cwd/
49•ejplatzer•12h ago•5 comments

Automatically generate all 3D print files for organizing a drawer

https://geniecrate.com/
50•woktalk•2d ago•26 comments

Everything old is new again: memory optimization

https://nibblestew.blogspot.com/2026/03/everything-old-is-new-again-memory.html
202•ibobev•4d ago•137 comments