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.

Gemini 3.8 Flash and 3.8 Flash Cyber

https://blog.google/innovation-and-ai/models-and-research/gemini-models/3-8-flash-and-3-8-flash-c...
527•bratao•3h ago•314 comments

A Note from LWN

https://lwn.net/Articles/1090585/
604•rwky•5h ago•123 comments

Paint.net 5.2 alpha now runs on Linux

https://forums.paint.net/topic/134562-paintnet-52-alpha-build-9739/
67•judah•1h ago•37 comments

I Don't Have a Smartphone

https://ploum.net/2026-09-02-i_dont_have_a_smartphone.html
66•speckx•54m ago•52 comments

Mistral now trains on user input by default, except on enterprise tier

https://help.mistral.ai/en/articles/455207-can-i-opt-out-of-my-input-or-output-data-being-used-fo...
279•teekert•6h ago•123 comments

Biggest dark matter detector spots a single weird particle

https://www.science.org/content/article/world-s-biggest-dark-matter-detector-spots-single-weird-p...
171•randycupertino•5h ago•40 comments

GrapheneOS says Pixel 11 has MTE support after all

https://grapheneos.social/@GrapheneOS/117194007157499435
150•user_7832•4h ago•96 comments

Exit the Cave

https://turtlespace.blog/p/exit-the-cave
129•akkartik•4h ago•28 comments

Three sites made 215,128 “best software” pages for AI. Perplexity cites them

https://trellner.com/reports/manufactured-sources-behind-ai-recommendations/
210•jakobgreenfeld•4h ago•104 comments

A third of Perplexity's citations don't contain the number they're cited for

https://hausresearch.com/reports/perplexity-citation-audit/
111•jakobgreenfeld•4h ago•39 comments

SteamdDB Joins Nexus Mods

https://www.nexusmods.com/news/15597
52•HelloUsername•3h ago•20 comments

Aging Brains Blend Memories Together Instead of Just Forgetting Them

https://studyfinds.com/aging-brains-blend-memories-together-instead-of-forgetting-them-study-finds/
119•mdp2021•5h ago•50 comments

A Selection of Los Alamos Rolodex Business Cards

https://clui.org/collections/los-alamos-business-cards/selection-cards
92•1970-01-01•1d ago•19 comments

Commodore 64 released September 1, 1982

https://dfarq.homeip.net/commodore-64-released-september-1-1982/
277•giuliomagnifico•10h ago•137 comments

Poisson Disk Sampling

https://stripeacross.com/posts/poisson-disk-sampling/
87•vismit2000•4h ago•12 comments

WebLLM: high-performance in-browser LLM inference engine

https://github.com/mlc-ai/web-llm
56•saikatsg•4h ago•12 comments

Making the Internet Boring

https://cemrehancavdar.com/2026/08/30/making-the-internet-boring/
16•zdw•2d ago•4 comments

Show HN: FrontierHarness Eval – 9 harness, same model, cost per pass varies 17x

https://frontierharness.org
43•shiqimei•2h ago•18 comments

Six curl CVEs after OpenAI and Anthropic came back with zero

https://aisle.com/blog/aisle-discovered-six-curl-cves-after-openai-and-anthropic-found-zero
132•goobreee•5h ago•46 comments

How to debloat your Xiaomi 15 Ultra without root access

https://trackerninja.codeberg.page/post/how-to-debloat-your-xiaomi-15-ultra-without-rooting-and-c...
19•spacedrone808•2h ago•11 comments

Discontinuation of third level domain registrations for the .name TLD [pdf]

https://itp.cdn.icann.org/en/files/consensus-policies/rsep-2026013-name-request-15-04-2026-en.pdf
29•greyface-•1d ago•16 comments

Why do so many tools have JSON config files?

https://textlog.cc/post/895
6•stagas•23m ago•5 comments

Tangle – Visual ML Pipeline Editor

https://tangleml.com/
13•duck•1h ago•1 comments

Check if a file was made with Claude

https://claude.com/check-content
111•frexs•6h ago•78 comments

Quasar 438B: Europe's Leading AI Model

https://multiversecomputing.com/resources/introducing-quasar-438b-europe-s-leading-ai-model
145•amunozo•8h ago•95 comments

Telli (YC F24) is hiring engineers and designers [Berlin, on-site]

https://careers.telli.com/
1•sebselassie•10h ago

LLMs: Intelligence vs. Cost

https://openteams.com/intelligence-vs-cost/
58•theanonymousone•5h ago•25 comments

The race to engineer new knobs for the human brain

https://www.neuroai.science/p/the-race-to-engineer-new-knobs-for
16•pminimax•2h ago•0 comments

The Emergent Symbolic Structure of Artificial Neural Networks

https://arxiv.org/abs/2608.29530
261•schmuhblaster•14h ago•88 comments

How Railroad Crossings Work

https://practical.engineering/blog/2023/12/29/how-railroad-crossings-work
18•at1as•1h ago•8 comments