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.

GLM 5.2 beats Claude in our benchmarks

https://semgrep.dev/blog/2026/we-have-mythos-at-home-glm-52-beats-claude-in-our-cyber-benchmarks/
544•jms703•9h ago•257 comments

Historical memory prices 1960-2026

https://dam.stanford.edu/memory-prices.html
206•vga1•8h ago•79 comments

Better Images of AI

https://betterimagesofai.org/
26•Curiositry•3h ago•15 comments

Knowledge Distillation of Black-Box Large Language Models (2024)

https://arxiv.org/abs/2401.07013
63•babelfish•4h ago•13 comments

5k menus from the New York Public Library’s Buttolph Collection (1880-1920)

https://pudding.cool/2026/06/menu-story/
340•xbryanx•12h ago•87 comments

AI boom risks global financial crash, warn central bankers

https://www.telegraph.co.uk/business/2026/06/28/ai-boom-risks-global-financial-crash-central-bank...
69•b-man•2h ago•52 comments

I used Claude Code to get a second opinion on my MRI

https://antoine.fi/mri-analysis-using-claude-code-opus
366•engmarketer•10h ago•476 comments

Deciphering Basmala

https://blog.plover.com/lang/bismillah.html
19•lordgrenville•4d ago•5 comments

Tell Congress: Don't Force Age Checks Online

https://act.eff.org/action/tell-congress-don-t-force-age-checks-online
41•rmason•1h ago•6 comments

TOP500 at ISC’26: We have a New Number 1 Supercomputer

https://chipsandcheese.com/p/top500-at-isc26-we-have-a-new-number
85•rbanffy•7h ago•41 comments

The Boeing 747 begins its final descent

https://www.theatlantic.com/magazine/2026/07/boeing-747-retirement/687304/
151•dbl000•3d ago•208 comments

Show HN: Zanagrams

https://zanagrams.com/
203•pompomsheep•12h ago•53 comments

Librepods: AirPods liberated

https://github.com/librepods-org/librepods
300•rbanffy•8h ago•97 comments

Professor denounces mass AI fraud on an exam at Brown

https://english.elpais.com/education/2026-06-28/ai-fraud-at-brown-university-academic-integrity-i...
307•geox•10h ago•407 comments

Working around dragons with the Lemote Yeeloong laptop and OpenBSD

http://oldvcr.blogspot.com/2026/06/working-around-dragons-with-lemote.html
94•zdw•10h ago•22 comments

The Baffling World of Masayoshi Son's Presentations (2020)

https://www.bloomberg.com/news/features/2020-06-23/golden-geese-and-unicorns-inside-the-eccentric...
26•phaser•2d ago•5 comments

Daisugi, the Japanese technique of growing trees out of other trees (2020)

https://www.openculture.com/2020/10/daisugi.html
117•MaysonL•11h ago•36 comments

Researchers have developed pixels that can emit and analyse light together

https://ethz.ch/en/news-and-events/eth-news/news/2026/06/a-new-type-of-pixel.html
51•tspng•1d ago•33 comments

Tokenmaxxing is dead, long live tokenmaxxing

https://12gramsofcarbon.com/p/agentics-tech-things-tokenmaxxing
118•theahura•11h ago•144 comments

Show HN: DRM-Free Books

https://frequal.com/Perspectives/DrmFreeAuthors.html
79•TeaVMFan•10h ago•34 comments

A way to exclude sensitive files issue still open for OpenAI Codex

https://github.com/openai/codex/issues/2847
181•pikseladam•15h ago•121 comments

The KIDS Act would require age checks to get online

https://www.eff.org/deeplinks/2026/06/kids-act-would-require-age-checks-get-online
341•bilsbie•15h ago•285 comments

Examining circuit boards from the Space Shuttle's I/O Processor

https://www.righto.com/2026/06/space-shuttle-io-processor-boards.html
88•pwg•11h ago•20 comments

You might not need a service worker

https://www.jayfreestone.com/writing/you-might-not-need-a-service-worker/
4•Fudgel•2h ago•0 comments

Model Training as Code

https://aleph-alpha.com/en/blog/model-training-as-code/
25•peterBlue75•3d ago•9 comments

The curious case of the disappearing Polish S (2015)

https://aresluna.org/the-curious-case-of-the-disappearing-polish-s/
211•colinprince•14h ago•71 comments

Show HN: Bash4LLM+ – A lightweight, dependency-free Bash wrapper for LLM APIs

https://github.com/kamaludu/bash4llm/
38•kamaludu•7h ago•15 comments

Show HN: NanoEuler – GPT-2 scale model in pure C/CUDA from scratch

https://github.com/JustVugg/nanoeuler
38•vforno•7h ago•9 comments

The MUMPS 76 Primer – anniversary edition

https://github.com/rochus-keller/MUMPS/blob/main/docs/MUMPS_Primer.adoc
72•Rochus•14h ago•42 comments

British Origami: the 1955 exhibition by Akira Yoshizawa (2005)

https://www.britishorigami.org/cp-lister-list/the-1955-exhibition-by-akira-yoshizawa/
22•dang•8h ago•2 comments