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

Comments

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

Bitwarden CLI Compromised in Ongoing Checkmarx Supply Chain Campaign

https://socket.dev/blog/bitwarden-cli-compromised
125•tosh•1h ago•35 comments

Show HN: Honker – Postgres NOTIFY/LISTEN Semantics for SQLite

https://github.com/russellromney/honker
123•russellthehippo•3h ago•20 comments

I am building a cloud

https://crawshaw.io/blog/building-a-cloud
725•bumbledraven•10h ago•375 comments

Your hex editor should color-code bytes

https://simonomi.dev/blog/color-code-your-bytes/
318•tobr•2d ago•98 comments

Alberta startup sells no-tech tractors for half price

https://wheelfront.com/this-alberta-startup-sells-no-tech-tractors-for-half-price/
1985•Kaibeezy•23h ago•667 comments

Investigation uncovers two sophisticated telecom surveillance campaigns

https://techcrunch.com/2026/04/23/surveillance-vendors-caught-abusing-access-to-telcos-to-track-p...
273•mentalgear•3h ago•83 comments

Apple fixes bug that cops used to extract deleted chat messages from iPhones

https://techcrunch.com/2026/04/22/apple-fixes-bug-that-cops-used-to-extract-deleted-chat-messages...
737•cdrnsf•19h ago•175 comments

Writing a C Compiler, in Zig (2025)

https://ar-ms.me/thoughts/c-compiler-1-zig/
70•tosh•6h ago•22 comments

The Onion to Take over InfoWars

https://www.nytimes.com/2026/04/20/business/infowars-alex-jones-the-onion.html
386•lxm•2d ago•166 comments

A Renaissance gambling dispute spawned probability theory

https://www.scientificamerican.com/article/how-a-renaissance-gambling-dispute-spawned-probability...
46•sohkamyung•2d ago•2 comments

We found a stable Firefox identifier linking all your private Tor identities

https://fingerprint.com/blog/firefox-tor-indexeddb-privacy-vulnerability/
826•danpinto•22h ago•239 comments

Isopods of the world

https://isopod.site/
80•debesyla•2d ago•35 comments

Jiga (YC W21) Is Hiring

https://jiga.io/about-us/
1•grmmph•3h ago

A History of Erasures Learning to Write Like Leylâ Erbil

https://thepointmag.com/criticism/a-history-of-erasures/
14•lermontov•2d ago•0 comments

5x5 Pixel font for tiny screens

https://maurycyz.com/projects/mcufont/
730•zdw•4d ago•149 comments

To Protect and Swerve: NYPD Cop Has 547 Speeding Tickets

https://nyc.streetsblog.org/2026/04/23/to-protect-and-swerve-nypd-cop-has-527-speeding-tickets-ye...
14•greedo•32m ago•2 comments

Raylib v6.0

https://github.com/raysan5/raylib/releases/tag/6.0
97•rydgel•3h ago•9 comments

Arch Linux Now Has a Bit-for-Bit Reproducible Docker Image

https://antiz.fr/blog/archlinux-now-has-a-reproducible-docker-image/
177•maxloh•13h ago•61 comments

Our newsroom AI policy

https://arstechnica.com/staff/2026/04/our-newsroom-ai-policy/
126•zdw•10h ago•91 comments

A True Life Hack: What Physical 'Life Force' Turns Biology's Wheels?

https://www.quantamagazine.org/what-physical-life-force-turns-biologys-wheels-20260420/
151•Prof_Sigmund•2d ago•27 comments

An amateur historian's favorite books about the Silk Road

https://bookdna.com/best-books/silk-road
59•bwb•2d ago•24 comments

Over-editing refers to a model modifying code beyond what is necessary

https://nrehiew.github.io/blog/minimal_editing/
391•pella•21h ago•230 comments

Website streamed live directly from a model

https://flipbook.page/
363•sethbannon•21h ago•95 comments

Highlights from Git 2.54

https://github.blog/open-source/git/highlights-from-git-2-54/
89•ingve•2d ago•46 comments

US Department of Justice has officially reclassified cannabis as less dangerous

https://www.bbc.com/news/articles/cdxd0xxp0jko
107•kaycebasques•2h ago•109 comments

Technical, cognitive, and intent debt

https://martinfowler.com/fragments/2026-04-02.html
300•theorchid•23h ago•79 comments

Ping-pong robot beats top-level human players

https://www.reuters.com/sports/ping-pong-robot-ace-makes-history-by-beating-top-level-human-playe...
154•wslh•1d ago•220 comments

Spam in conversational replies to blog posts

https://shkspr.mobi/blog/2026/04/sneaky-spam-in-conversational-replies-to-blog-posts/
73•ColinWright•3h ago•58 comments

Books are not too expensive

https://www.millersbookreview.com/p/no-books-are-not-remotely-too-expensive
94•herbertl•3d ago•122 comments

Parallel agents in Zed

https://zed.dev/blog/parallel-agents
259•ajeetdsouza•22h ago•146 comments