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

Comments

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

Show HN: Brutalist Concrete Laptop Stand (2024)

https://sam-burns.com/posts/concrete-laptop-stand/
390•sam-bee•5h ago•147 comments

Cloudflare targets 2029 for full post-quantum security

https://blog.cloudflare.com/post-quantum-roadmap/
58•ilreb•2h ago•21 comments

Moving fast in hardware: lessons from lab to $100M ARR

https://blog.zacka.io/p/simplify-then-add-lightness-bc4
25•rryan•1h ago•4 comments

We found an undocumented bug in the Apollo 11 guidance computer code

https://www.juxt.pro/blog/a-bug-on-the-dark-side-of-the-moon/
275•henrygarner•5h ago•143 comments

Good Taste the Only Real Moat Left

https://rajnandan.com/posts/taste-in-the-age-of-ai-and-llms/
23•speckx•23m ago•10 comments

Dropping Cloudflare for Bunny.net

https://jola.dev/posts/dropping-cloudflare
221•shintoist•2h ago•101 comments

Claude Code is locking people out for hours

https://github.com/anthropics/claude-code/issues/44257
144•sh1mmer•1h ago•145 comments

Show HN: A cartographer's attempt to realistically map Tolkien's world

https://www.intofarlands.com/atlasofarda
92•intofarlands•4h ago•16 comments

Every GPU That Mattered

https://sheets.works/data-viz/every-gpu
239•jonbaer•7h ago•129 comments

You can't cancel a JavaScript promise (except sometimes you can)

https://www.inngest.com/blog/hanging-promises-for-control-flow
38•goodoldneon•2h ago•26 comments

9 Mothers (YC P26) Is Hiring – Lead Robotics and More

https://jobs.ashbyhq.com/9-mothers?utm_source=x8pZ4B3P3Q
1•ukd1•2h ago

Identify a London Underground Line just by listening to it

https://tubesoundquiz.com/
132•nelson687•6h ago•41 comments

Global Physics Photowalk: 2025 winners revealed

https://www.quantamagazine.org/global-physics-photowalk-2025-winners-revealed-20260401/
10•ibobev•3d ago•1 comments

SQLite in Production: Lessons from Running a Store on a Single File

https://ultrathink.art/blog/sqlite-in-production-lessons
78•thunderbong•3d ago•57 comments

My Experience as a Rice Farmer

https://xd009642.github.io/2026/04/01/My-Experience-as-a-Rice-Farmer.html
287•surprisetalk•5d ago•134 comments

Wi-Fi That Can Withstand a Nuclear Reactor: This receiver chip can take it

https://spectrum.ieee.org/robotics-in-nuclear-industry
53•voxadam•4d ago•2 comments

DeiMOS – A Superoptimizer for the MOS 6502

https://aransentin.github.io/deimos/
51•Aransentin•5h ago•15 comments

Show HN: Stop paying for Dropbox/Google Drive, use your own S3 bucket instead

https://locker.dev
181•Zm44•5h ago•146 comments

Blackholing My Email

https://www.johnsto.co.uk/blog/blackholing-my-email/
122•semyonsh•7h ago•13 comments

Haunting Photos Show the Aftermath of the Kursk Submarine Disaster in 2000

https://rarehistoricalphotos.com/kursk-submarine-disaster-photos/
96•mooreds•4d ago•22 comments

Show HN: Pion/handoff – Move WebRTC out of browser and into Go

https://github.com/pion/handoff
63•Sean-Der•4h ago•11 comments

Running Out of Disk Space in Production

https://alt-romes.github.io/posts/2026-04-01-running-out-of-disk-space-on-launch.html
110•romes•4d ago•50 comments

12k Tons of Dumped Orange Peel Grew into a Landscape Nobody Expected (2017)

https://www.sciencealert.com/how-12-000-tonnes-of-dumped-orange-peel-produced-something-nobody-im...
22•pulisse•30m ago•1 comments

AI may be making us think and write more alike

https://dornsife.usc.edu/news/stories/ai-may-be-making-us-think-and-write-more-alike/
170•giuliomagnifico•4h ago•163 comments

Breaking the console: a brief history of video game security

https://sergioprado.blog/breaking-the-console-a-brief-history-of-video-game-security/
64•sprado•6h ago•18 comments

Sam Altman may control our future – can he be trusted?

https://www.newyorker.com/magazine/2026/04/13/sam-altman-may-control-our-future-can-he-be-trusted
1786•adrianhon•1d ago•729 comments

Show HN: Ghost Pepper – Local hold-to-talk speech-to-text for macOS

https://github.com/matthartman/ghost-pepper
432•MattHart88•20h ago•190 comments

Record wind and solar saved UK from gas imports worth £1B in March 2026

https://www.carbonbrief.org/analysis-record-wind-and-solar-saved-uk-from-gas-imports-worth-1bn-in...
85•mindracer•4h ago•56 comments

Floating point from scratch: Hard Mode

https://essenceia.github.io/projects/floating_dragon/
72•random__duck•2d ago•16 comments

Three hundred synths, 3 hardware projects, and one app

https://midi.guide/blog/three-hunded-synths-one-app/
103•ductionist•11h ago•13 comments