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.

Canvas is down as ShinyHunters threatens to leak schools’ data

https://www.theverge.com/tech/926458/canvas-shinyhunters-breach
378•stefanpie•5h ago•271 comments

Maybe you shouldn't install new software for a bit

https://xeiaso.net/blog/2026/abstain-from-install/
253•psxuaw•5h ago•110 comments

Dirtyfrag: Universal Linux LPE

https://www.openwall.com/lists/oss-security/2026/05/07/8
480•flipped•8h ago•207 comments

Cloudflare to cut about 20% workforce

https://www.reuters.com/business/world-at-work/cloudflare-cut-over-1100-jobs-2026-05-07/
348•PriorityLeft•7h ago•208 comments

The map that keeps Burning Man honest

https://www.not-ship.com/burning-man-moop/
570•speckx•14h ago•294 comments

Pinocchio is weirder than you remembered

https://storica.club/blog/pinocchio-in-italian/
40•cemsakarya•1d ago•3 comments

Agents need control flow, not more prompts

https://bsuh.bearblog.dev/agents-need-control-flow/
368•bsuh•11h ago•196 comments

Plasticity and language in the anaesthetized human hippocampus

https://www.bcm.edu/news/researchers-discover-advanced-language-processing-in-the-unconscious-hum...
71•hhs•4h ago•26 comments

Natural Language Autoencoders: Turning Claude's Thoughts into Text

https://www.anthropic.com/research/natural-language-autoencoders
223•instagraham•10h ago•72 comments

GNU IFUNC is the real culprit behind CVE-2024-3094

https://github.com/robertdfrench/ifuncd-up
37•foltik•4h ago•12 comments

AlphaEvolve: Gemini-powered coding agent scaling impact across fields

https://deepmind.google/blog/alphaevolve-impact/
261•berlianta•13h ago•110 comments

Gambling ads on social media reach more than twice as many men as women: study

https://www.cam.ac.uk/research/news/gambling-ads-on-social-media-reach-more-than-twice-as-many-me...
28•hhs•4h ago•9 comments

DeepSeek 4 Flash local inference engine for Metal

https://github.com/antirez/ds4
325•tamnd•12h ago•95 comments

Komai: a fine Matrix chat app you can get to love

https://etke.cc/blog/introducing-komai
31•anotherevan•3h ago•11 comments

Nonprofit hospitals spend billions on consultants with no clear effect

https://www.uchicagomedicine.org/forefront/research-and-discoveries-articles/nonprofit-hospitals-...
97•hhs•5h ago•30 comments

Los Alamos and the long path to detecting neutrinos

https://www.lanl.gov/media/publications/1663/from-ghost-particle-to-cosmic-messenger
7•LAsteNERD•1d ago•0 comments

AI slop is killing online communities

https://rmoff.net/2026/05/06/ai-slop-is-killing-online-communities/
507•thm•9h ago•470 comments

Brazil's Pix payment system faces pressure from Visa and Mastercard

https://www.elciudadano.com/en/brazils-pix-payment-system-faces-pressure-from-visa-and-mastercard...
119•wslh•10h ago•79 comments

New York state set to ban law enforcement, including ICE, from wearing masks

https://www.reuters.com/legal/government/new-york-state-set-ban-law-enforcement-including-ice-wea...
16•tartoran•29m ago•2 comments

The Disappearance of the Public Bench

https://placesjournal.org/article/the-disappearance-of-the-public-bench/
65•cainxinth•1d ago•53 comments

Singapore introduces caning for boys who bully others at school

https://www.theguardian.com/world/2026/may/06/singapore-caning-school-bullies
93•rustoo•1d ago•104 comments

I want to live like Costco people

https://tastecooking.com/i-want-to-live-like-costco-people/
261•speckx•12h ago•541 comments

Two Home Affairs officials suspended after AI 'hallucinations' found

https://www.citizen.co.za/news/home-affairs-officials-suspended-ai-hallucinations/
63•jruohonen•8h ago•17 comments

Hardening Firefox with Claude Mythos Preview

https://hacks.mozilla.org/2026/05/behind-the-scenes-hardening-firefox/
94•HieronymusBosch•12h ago•64 comments

The Traveling Salesdog Problem

https://www.wespiser.com/posts/2026-05-04-traveling-salesdog.html
20•wespiser_2018•2d ago•4 comments

Chrome removes claim of On-device Al not sending data to Google Servers

https://old.reddit.com/r/chrome/comments/1t5qayz/chrome_removes_claim_of_ondevice_al_not_sending/
499•newsoftheday•12h ago•191 comments

Principles for agent-native CLIs

https://twitter.com/trevin/status/2051316002730991795
72•blumpy22•10h ago•42 comments

Creating for a niche

https://www.davesnider.com/posts/working-in-a-niche
36•snide•8h ago•6 comments

Programming Still Sucks

https://www.stvn.sh/writing/programming-still-sucks-fqffhyp
508•jeromechoo•1d ago•279 comments

Tools in the Grass: Raising the next generation of crafts person

https://www.popularwoodworking.com/editors-blog/tools-in-the-grass/
36•NaOH•2d ago•3 comments