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•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.

Redox OS has adopted a Certificate of Origin policy and a strict no-LLM policy

https://gitlab.redox-os.org/redox-os/redox/-/blob/master/CONTRIBUTING.md
118•pjmlp•1h ago•105 comments

Lotus 1-2-3 on the PC with DOS

https://stonetools.ghost.io/lotus123-dos/
101•TMWNN•3d ago•35 comments

Two Years of Emacs Solo

https://www.rahuljuliato.com/posts/emacs-solo-two-years
267•celadevra_•10h ago•78 comments

LoGeR – 3D reconstruction from extremely long videos (DeepMind, UC Berkeley)

https://loger-project.github.io
43•helloplanets•4h ago•17 comments

Building a Procedural Hex Map with Wave Function Collapse

https://felixturner.github.io/hex-map-wfc/article/
498•imadr•17h ago•72 comments

Optimizing Top K in Postgres

https://www.paradedb.com/blog/optimizing-top-k
84•philippemnoel•1d ago•11 comments

A useless infinite scroll experiment

https://futile.ch/en/
71•dolin_ch•3d ago•38 comments

Show HN: Remotely use my guitar tuner

https://realtuner.online/
199•smith-kyle•3d ago•43 comments

The Gervais Principle, or the Office According to "The Office"

https://www.ribbonfarm.com/2009/10/07/the-gervais-principle-or-the-office-according-to-the-office/
23•janandonly•2d ago•5 comments

JSLinux Now Supports x86_64

https://bellard.org/jslinux/
328•TechTechTech•18h ago•99 comments

Is legal the same as legitimate: AI reimplementation and the erosion of copyleft

https://writings.hongminhee.org/2026/03/legal-vs-legitimate/
474•dahlia•19h ago•495 comments

The hidden compile-time cost of C++26 reflection

https://vittorioromeo.com/index/blog/refl_compiletime.html
24•SuperV1234•3d ago•4 comments

macOS Tahoe windows have different corner radiuses

https://lapcatsoftware.com/articles/2026/3/1.html
166•robenkleene•3d ago•116 comments

No, it doesn't cost Anthropic $5k per Claude Code user

https://martinalderson.com/posts/no-it-doesnt-cost-anthropic-5k-per-claude-code-user/
233•jnord•11h ago•168 comments

Show HN: I Was Here – Draw on street view, others can find your drawings

https://washere.live
29•mrktsm__•5h ago•22 comments

Darkrealms BBS

http://www.darkrealms.ca/
105•TigerUniversity•3d ago•23 comments

The “JVG algorithm” only wins on tiny numbers

https://scottaaronson.blog/?p=9615
69•jhalderm•10h ago•38 comments

TCXO Failure Analysis

https://serd.es/2026/03/06/TCXO-failure-analysis.html
4•zdw•3d ago•0 comments

Learnings from paying artists royalties for AI-generated art

https://www.kapwing.com/blog/learnings-from-paying-artists-royalties-for-ai-generated-art/
135•jenthoven•8h ago•111 comments

Show HN: DenchClaw – Local CRM on Top of OpenClaw

https://github.com/DenchHQ/DenchClaw
120•kumar_abhirup•19h ago•96 comments

Graphing how the 10k* most common English words define each other

https://wyattsell.com/experiments/word-graph/
67•wyattsell•2d ago•18 comments

DARPA’s new X-76

https://www.darpa.mil/news/2026/darpa-new-x-76-speed-of-jet-freedom-of-helicopter
204•newer_vienna•17h ago•182 comments

Launch HN: Terminal Use (YC W26) – Vercel for filesystem-based agents

101•filipbalucha•17h ago•73 comments

Getting Started in Common Lisp

https://lisp-stat.dev/blog/2026/03/09/getting-started/
48•oumua_don17•11h ago•9 comments

An opinionated take on how to do important research that matters

https://nicholas.carlini.com/writing/2026/how-to-win-a-best-paper-award.html
134•mad•18h ago•33 comments

Notes on Baking at the South Pole

https://www.newyorker.com/culture/the-weekend-essay/the-most-beautiful-freezer-in-the-world
62•mitchbob•15h ago•22 comments

Florida judge rules red light camera tickets are unconstitutional

https://cbs12.com/news/local/florida-news-judge-rules-red-light-camera-tickets-unconstitutional
430•1970-01-01•17h ago•552 comments

OpenAI is walking away from expanding its Stargate data center with Oracle

https://www.cnbc.com/2026/03/09/oracle-is-building-yesterdays-data-centers-with-tomorrows-debt.html
361•spenvo•14h ago•215 comments

Ireland shuts last coal plant, becomes 15th coal-free country in Europe (2025)

https://www.pv-magazine.com/2025/06/20/ireland-coal-free-ends-coal-power-generation-moneypoint/
971•robin_reala•1d ago•608 comments

No leap second will be introduced at the end of June 2026

https://lists.iana.org/hyperkitty/list/tz@iana.org/thread/P6D36VZSZBUSSTSMZKFXKF4T4IXWN23P/
116•speckx•22h ago•127 comments