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•9mo ago

Comments

LegionMammal978•9mo 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•9mo 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•9mo 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.

CasNum

https://github.com/0x0mer/CasNum
154•aebtebeten•3h ago•22 comments

A decade of Docker containers

https://cacm.acm.org/research/a-decade-of-docker-containers/
219•zacwest•7h ago•157 comments

Dumping Lego NXT firmware off of an existing brick (2025)

https://arcanenibble.github.io/dumping-lego-nxt-firmware-off-of-an-existing-brick.html
136•theblazehen•1d ago•9 comments

Effort to prevent government officials from engaging in prediction markets

https://www.merkley.senate.gov/merkley-klobuchar-launch-new-effort-to-ban-federal-elected-officia...
189•stopbulying•3h ago•67 comments

The Day NY Publishing Lost Its Soul

https://www.honest-broker.com/p/the-day-ny-publishing-lost-its-soul
34•wallflower•3h ago•21 comments

Ghostmd: Ghostty but for Markdown Notes

https://mimoo.github.io/ghostmd/
3•baby•30m ago•0 comments

Ki Editor - an editor that operates on the AST

https://ki-editor.org/
354•ravenical•14h ago•129 comments

In 1985 Maxell built a bunch of life-size robots for its bad floppy ad

https://buttondown.com/suchbadtechads/archive/maxell-life-size-robots/
55•rfarley04•3d ago•4 comments

Put the zip code first

https://zipcodefirst.com
171•dsalzman•1h ago•126 comments

Package managers need to cool down

https://nesbitt.io/2026/03/04/package-managers-need-to-cool-down.html
37•zdw•3d ago•26 comments

Caitlin Kalinowski: I resigned from OpenAI

https://twitter.com/kalinowski007/status/2030320074121478618
45•mmaia•1h ago•19 comments

macOS code injection for fun and no profit (2024)

https://mariozechner.at/posts/2024-07-20-macos-code-injection-fun/
61•jstrieb•3d ago•10 comments

FLASH radiotherapy's bold approach to cancer treatment

https://spectrum.ieee.org/flash-radiotherapy
180•marc__1•9h ago•55 comments

Autoresearch: Agents researching on single-GPU nanochat training automatically

https://github.com/karpathy/autoresearch
29•simonpure•4h ago•6 comments

LLM Writing Tropes.md

https://tropes.fyi/tropes-md
69•walterbell•3h ago•27 comments

The influence of anxiety: Harold Bloom and literary inheritance

https://thepointmag.com/examined-life/the-influence-of-anxiety/
6•apollinaire•3d ago•0 comments

How important was the Battle of Hastings?

https://www.historytoday.com/archive/head-head/how-important-was-battle-hastings
4•benbreen•3d ago•2 comments

The surprising whimsy of the Time Zone Database

https://muddy.jprs.me/links/2026-03-06-the-surprising-whimsy-of-the-time-zone-database/
30•jprs•6h ago•1 comments

Why developers using AI are working longer hours

https://www.scientificamerican.com/article/why-developers-using-ai-are-working-longer-hours/
26•birdculture•59m ago•14 comments

SigNoz (YC W21, open source Datadog) Is Hiring across roles

https://signoz.io/careers
1•pranay01•7h ago

Compiling Prolog to Forth [pdf]

https://vfxforth.com/flag/jfar/vol4/no4/article4.pdf
93•PaulHoule•4d ago•9 comments

Re-creating the complex cuisine of prehistoric Europeans

https://arstechnica.com/science/2026/03/recreating-the-complex-cuisine-of-prehistoric-europeans/
61•apollinaire•1d ago•23 comments

Lisp-style C++ template meta programming

https://github.com/mistivia/lmp
6•mistivia•2h ago•0 comments

Ask HN: Would you use a job board where every listing is verified?

21•BelVisgarra•3h ago•39 comments

Trampolining Nix with GenericClosure

https://blog.kleisli.io/post/trampolining-nix-with-generic-closure
6•ret2pop•2d ago•1 comments

The yoghurt delivery women combatting loneliness in Japan

https://www.bbc.com/travel/article/20260302-the-yoghurt-delivery-women-combatting-loneliness-in-j...
192•ranit•11h ago•121 comments

Show HN: ANSI-Saver – A macOS Screensaver

https://github.com/lardissone/ansi-saver
86•lardissone•10h ago•27 comments

Files are the interface humans and agents interact with

https://madalitso.me/notes/why-everyone-is-talking-about-filesystems/
169•malgamves•13h ago•105 comments

Self-Portrait by Ernst Mach (1886)

https://publicdomainreview.org/collection/self-portrait-by-ernst-mach-1886/
87•Hooke•2d ago•16 comments

$3T flows through U.S. nonprofits every year

https://charitysense.com/insights/the-3-trillion-blind-spot
88•mtweak•2h ago•54 comments