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.

LinkedIn Is Illegally Searching Your Computer

https://browsergate.eu/
477•digitalWestie•1h ago•222 comments

Lemonade by AMD: a fast and open source local LLM server using GPU and NPU

https://lemonade-server.ai
173•AbuAssar•3h ago•37 comments

Qwen3.6-Plus: Towards Real World Agents

https://qwen.ai/blog?id=qwen3.6
11•pretext•19m ago•1 comments

Inside Nepal's Fake Rescue Racket

https://kathmandupost.com/money/2026/03/27/inside-nepal-s-fake-rescue-racket
110•lode•3h ago•30 comments

IBM Announces Strategic Collaboration with Arm

https://newsroom.ibm.com/2026-04-02-ibm-announces-strategic-collaboration-with-arm-to-shape-the-f...
181•bonzini•5h ago•108 comments

Sweden goes back to basics, swapping screens for books in the classroom

https://undark.org/2026/04/01/sweden-schools-books/
349•novaRom•3h ago•189 comments

Significant Raise of Reports

https://lwn.net/Articles/1065620/
114•stratos123•5h ago•60 comments

Bringing Clojure programming to Enterprise (2021)

https://blogit.michelin.io/clojure-programming/
118•smartmic•6h ago•60 comments

'Backrooms' and the Rise of the Institutional Gothic

https://thereader.mitpress.mit.edu/backrooms-and-the-rise-of-the-institutional-gothic/
10•anarbadalov•1h ago•2 comments

Gone (Almost) Phishin'

https://ma.tt/2026/03/gone-almost-phishin/
98•luu•2d ago•48 comments

Enabling Codex to Analyze Two Decades of Hacker News Data

https://modolap.com/publication/hn-analysis-1
34•ronfriedhaber•4h ago•11 comments

Email obfuscation: What works in 2026?

https://spencermortensen.com/articles/email-obfuscation/
237•jaden•11h ago•70 comments

Emacs-libgterm: Terminal emulator for Emacs using libghostty-vt

https://github.com/rwc9u/emacs-libgterm
35•signa11•4d ago•7 comments

Mercor says it was hit by cyberattack tied to compromise LiteLLM

https://techcrunch.com/2026/03/31/mercor-says-it-was-hit-by-cyberattack-tied-to-compromise-of-ope...
97•jackson-mcd•1d ago•30 comments

Reinventing the Pull Request

https://lubeno.dev/blog/reinventing-the-pull-request
46•bkolobara•6d ago•33 comments

Show HN: I built a DNS resolver from scratch in Rust – no DNS libraries

https://github.com/razvandimescu/numa
33•rdme•4h ago•23 comments

Quantum computing bombshells that are not April Fools

https://scottaaronson.blog/?p=9665
226•Strilanc•14h ago•71 comments

Steam on Linux Use Skyrocketed Above 5% in March

https://www.phoronix.com/news/Steam-On-Linux-Tops-5p
570•hkmaxpro•11h ago•267 comments

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

http://hi.telli.com/join-us
1•sebselassie•7h ago

EmDash – A spiritual successor to WordPress that solves plugin security

https://blog.cloudflare.com/emdash-wordpress/
625•elithrar•22h ago•467 comments

Subscription bombing and how to mitigate it

https://bytemash.net/posts/subscription-bombing-your-signup-form-is-a-weapon/
230•homelessdino•10h ago•149 comments

Artemis II Launch Day Updates

https://www.nasa.gov/blogs/missions/2026/04/01/live-artemis-ii-launch-day-updates/
1006•apitman•21h ago•877 comments

Built a cheap DIY fan controller because my motherboard never had working PWM

https://www.himthe.dev/blog/msi-forgot-my-fans
54•bobsterlobster•2d ago•17 comments

A new C++ back end for ocamlc

https://github.com/ocaml/ocaml/pull/14701
217•glittershark•15h ago•18 comments

New laws to make it easier to cancel subscriptions and get refunds

https://www.bbc.co.uk/news/articles/cvg0v36ek2go
116•chrisjj•5h ago•50 comments

DRAM pricing is killing the hobbyist SBC market

https://www.jeffgeerling.com/blog/2026/dram-pricing-is-killing-the-hobbyist-sbc-market/
553•ingve•17h ago•484 comments

Order and Tension

https://slab.org/2026/03/22/order-and-tension/
13•surprisetalk•3d ago•0 comments

ReactOS Shows Improved Stability and 64-Bit Support at Chemnitz Linux Days 2026

https://old.reddit.com/r/reactos/comments/1sa26yu/back_from_chemnitz_linux_days_2026/
40•jeditobe•2h ago•9 comments

Fast and Gorgeous Erosion Filter

https://blog.runevision.com/2026/03/fast-and-gorgeous-erosion-filter.html
205•runevision•2d ago•20 comments

Trap a quantum object in a box – is it hard or soft, or is it black or white?

https://paradigmsage.com/pop/ch-04-qm/
3•allangoff•1d ago•0 comments