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.

Zed 1.0

https://zed.dev/blog/zed-1-0
1463•salkahfi•9h ago•463 comments

Copy Fail – CVE-2026-31431

https://copy.fail/
484•unsnap_biceps•6h ago•224 comments

Germany has become the largest ammunition producer in the world

https://prm.ua/en/the-us-is-no-longer-the-leader-germany-has-become-the-largest-ammunition-produc...
103•doener•2h ago•63 comments

HERMES.md in commit messages causes requests to route to extra usage billing

https://github.com/anthropics/claude-code/issues/53262
944•homebrewer•5h ago•387 comments

OpenTrafficMap

https://opentrafficmap.org/
127•moooo99•4h ago•26 comments

Cursor Camp

https://neal.fun/cursor-camp/
539•bpierre•8h ago•98 comments

FastCGI: 30 years old and still the better protocol for reverse proxies

https://www.agwa.name/blog/post/fastcgi_is_the_better_protocol_for_reverse_proxies
224•agwa•7h ago•52 comments

> Be Alexandra Elbakyan

https://nitter.space/MushtaqBilalPhD/status/2049057344013881523#m
29•DanielleMolloy•1h ago•2 comments

Why I still reach for Lisp and Scheme instead of Haskell

https://jointhefreeworld.org/blog/articles/lisps/why-i-still-reach-for-scheme-instead-of-haskell/...
153•jjba23•15h ago•43 comments

DRAM Crunch: Lessons for System Design

https://www.eetimes.com/what-the-dram-crunch-teaches-us-about-system-design/
18•giuliomagnifico•1d ago•0 comments

Gooseworks (YC W23) Is Hiring a Founding Growth Engineer

https://www.ycombinator.com/companies/gooseworks/jobs/ztgY6bD-founding-growth-engineer
1•shivsak•2h ago

Laws of UX

https://lawsofux.com/
161•bobbiechen•7h ago•29 comments

Vera: a programming language designed for machines to write

https://github.com/aallan/vera
28•unignorant•2h ago•13 comments

An open-source stethoscope that costs between $2.5 and $5 to produce

https://github.com/GliaX/Stethoscope
179•0x54MUR41•9h ago•73 comments

Ramp's Sheets AI Exfiltrates Financials

https://www.promptarmor.com/resources/ramps-sheets-ai-exfiltrates-financials
95•takira•6h ago•32 comments

Third Editor Fired in Elsevier's Citation Cartel Crackdown

https://www.chrisbrunet.com/p/third-editor-fired-in-elseviers-citation
230•RigbyTaro•8h ago•76 comments

Soft launch of open-source code platform for government

https://www.nldigitalgovernment.nl/news/soft-launch-for-government-open-source-code-platform/
518•e12e•15h ago•117 comments

Kyoto cherry blossoms now bloom earlier than at any point in 1,200 years

https://jivx.com/kyoto-bloom
212•momentmaker•4h ago•57 comments

Postgres's lateral joins allow for quite the good eDSL

https://bensimms.moe/postgres-lateral-makes-quite-a-good-dsl/
43•nitros•2d ago•3 comments

We need a federation of forges

https://blog.tangled.org/federation/
508•icy•10h ago•322 comments

What can we gain by losing infinity?

https://www.quantamagazine.org/what-can-we-gain-by-losing-infinity-20260429/
5•Tomte•8h ago•0 comments

Online age verification is the hill to die on

https://x.com/GlennMeder/status/2049088498163216560
701•Cider9986•8h ago•441 comments

The Lingua Franca of LaTeX

https://increment.com/open-source/the-lingua-franca-of-latex/
6•ripe•1d ago•0 comments

How to Build the Future: Demis Hassabis [video]

https://www.youtube.com/watch?v=JNyuX1zoOgU
76•sandslash•10h ago•38 comments

I benchmarked Claude Code's caveman plugin against "be brief."

https://www.maxtaylor.me/articles/i-benchmarked-caveman-against-two-words
19•max-t-dev•3h ago•9 comments

Ghostty is leaving GitHub

https://mitchellh.com/writing/ghostty-leaving-github
3331•WadeGrimridge•1d ago•988 comments

Virtualisation on Apple Silicon Macs is different

https://eclecticlight.co/2026/04/29/virtualisation-on-apple-silicon-macs-is-different/
66•zdw•7h ago•15 comments

Maryland becomes first state to ban surveillance pricing in grocery stores

https://www.theguardian.com/technology/2026/apr/29/maryland-grocery-stores-ban-surveillance-pricing
222•01-_-•7h ago•161 comments

GitHub – DOS 1.0: Transcription of Tim Paterson's DOS Printouts

https://github.com/DOS-History/Paterson-Listings
118•s2l•12h ago•6 comments

Mistral Medium 3.5

https://mistral.ai/news/vibe-remote-agents-mistral-medium-3-5
413•meetpateltech•8h ago•195 comments