frontpage.
newsnewestaskshowjobs

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•1y ago

Comments

LegionMammal978•1y 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•1y 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•1y 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.

The UK's War on Anonymity Has Come to America

https://www.effort.news/uk-lobby
47•slowin•1h ago•3 comments

Muse Glimmer: 30B-parameter model optimized for always-on local agent workflows

https://research.meta.ai/blog/introducing-muse-glimmer-open-agentic-model
1019•riordan•14h ago•570 comments

Show HN: Needle2: 14MB agentic LLM for phones, wearables, smart home and robots

https://cactuscompute.com/needle
142•HenryNdubuaku•7h ago•67 comments

Show HN: Scroll through all 43252003274489856000 Rubik's Cube states

https://everycube.alen.is/
24•Alen123•1h ago•2 comments

Mark Zuckerberg attacks 'closed' AI rivals as Meta returns to open models

https://www.ft.com/content/4e3957f8-ea7c-4c46-a3de-cdce8e526878
350•root-parent•10h ago•365 comments

The "mechanical miracle" that ruined Mark Twain's life

https://resobscura.substack.com/p/the-mechanical-miracle-that-ruined
18•benbreen•5d ago•4 comments

Publishing Schematics Before “Open Source” Was a Word

https://fabscene.medium.com/publishing-schematics-before-open-source-was-a-word-55-years-of-akizu...
59•extralongdivisi•3d ago•14 comments

Sonic Pi v5

https://www.patreon.com/samaaron/posts/sonic-pi-v5-166001392
299•samaaron•3d ago•76 comments

Rust SIMD on the GPU

https://www.vectorware.com/blog/simd-on-gpu/
116•sagacity•6h ago•58 comments

Confessions of a Long-Distance Sailor

https://arachnoid.com/lutusp/sailbook.html
53•AntiRush•3h ago•10 comments

Stop Killing Games: It's time to sue Sony, join us

https://www.massaschadeconsument.nl/collectieve-acties/playstation/
144•EDM115•3h ago•58 comments

World Train Map – 1247 train routes around the world

https://worldtrainmap.com/
17•Flightmussy•2h ago•3 comments

Stowaway – take the window seat on any plane or satellite overhead

https://stowaway.live/
92•thunderbong•3d ago•11 comments

Squeak 6.1

https://squeak.org/release_notes/6.1/
218•fniephaus•12h ago•112 comments

Exploiting System Management Mode with a very long interrupt

https://github.com/xoreaxeaxeax/smiiiiiiiiiiiiiiii
120•WhiteDawn•8h ago•40 comments

Humanising LLM Outputs Is Dumb

https://kuber.studio/blog/Reflections/Humanising-LLM-Outputs-is-Actually-Dumb
148•kuberwastaken•11h ago•87 comments

Launch HN: Stoa Markets (YC S26) – A Marketplace for GPUs and AI Servers

https://www.stoaexchange.com
63•erenberke•8h ago•39 comments

What's the best programming language for coding agents?

http://danluu.com/pl-tokens/
44•chaychoong•8h ago•21 comments

The Psychedelic Toad of the Sonoran Desert

https://en.wikipedia.org/wiki/Bufo_Alvarius:_the_Psychedelic_Toad_of_the_Sonoran_Desert
75•simonebrunozzi•6d ago•52 comments

Ask HN: In your experience, what are sound conventions for e-ink UI development?

139•BoxOfRain•3d ago•50 comments

Parametron: 50s Japanese computer that uses neither transistors nor vacuum tubes

https://ethw.org/Milestones:Parametron,_1954
182•xeonmc•14h ago•45 comments

Letter to Governor Abbott on responsible AI infrastructure in Texas

https://openai.com/index/responsible-ai-infrastructure-texas/
86•hackerBanana•10h ago•164 comments

Google Search Is Dying. What Comes Next Is Worse

https://thewalrus.ca/google-search-is-dying/
77•awnird•2h ago•66 comments

Exploring Claude/GPT Knowledge Cutoffs and Pre-Training Timelines

https://blog.sshh.io/p/exploring-claudegpt-knowledge-cutoffs
94•sshh12•10h ago•14 comments

Magnitude 7.4 Earthquake – 5 km S of San José del Palmar, Colombia

https://earthquake.usgs.gov/earthquakes/eventpage/us6000tjl2/executive
160•Bender•8h ago•62 comments

Tail-call optimization in C is relatively recent (2025)

https://lwn.net/Articles/1034703/
119•prakashqwerty•13h ago•115 comments

50k Boat Names

https://www.beautifulpublicdata.com/boat-names/
152•jonathanmkeegan•11h ago•103 comments

Extreme 220GHz+Broadband Silicon Capacitor X2SC 0201M 22nF BV11

https://pim.murata.com/asset/pim4/siliconCapacitor/SICAP_X2SC422522_PDF_SILICONCAPACITOR
60•peter_d_sherman•8h ago•25 comments

Mistral Patent for “Code implemented tool calls”

https://patentsgazette.uspto.gov/week26/OG/html/1547-5/US12670045-20260630.html
207•theanonymousone•11h ago•171 comments

Tl;dv: Over 180k meetings left wide open

https://bobdahacker.com/blog/tldv-hack
527•colesantiago•12h ago•173 comments