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.

Rust Project Perspectives on AI

https://nikomatsakis.github.io/rust-project-perspectives-on-ai/feb27-summary.html
35•weinzierl•38m ago•6 comments

GrapheneOS will remain usable by anyone without requiring personal information

https://grapheneos.social/@GrapheneOS/116261301913660830
51•nothrowaways•1h ago•8 comments

PC Gamer recommends RSS readers in a 37mb article that just keeps downloading

https://stuartbreckenridge.net/2026-03-19-pc-gamer-recommends-rss-readers-in-a-37mb-article/
214•JumpCrisscross•4h ago•97 comments

The gold standard of optimization: A look under the hood of RollerCoaster Tycoon

https://larstofus.com/2026/03/22/the-gold-standard-of-optimization-a-look-under-the-hood-of-rolle...
102•mariuz•3h ago•31 comments

The future of version control

https://bramcohen.com/p/manyana
344•c17r•7h ago•197 comments

Reports of code's death are greatly exaggerated

https://stevekrouse.com/precision
186•stevekrouse•11h ago•178 comments

LLMs Predict My Coffee

https://dynomight.net/coffee/
36•surprisetalk•4d ago•11 comments

Project Nomad – Knowledge That Never Goes Offline

https://www.projectnomad.us
331•jensgk•10h ago•86 comments

Five Years of Running a Systems Reading Group at Microsoft

https://armaansood.com/posts/systems-reading-group/
92•Foe•5h ago•23 comments

Flash-MoE: Running a 397B Parameter Model on a Laptop

https://github.com/danveloper/flash-moe
281•mft_•11h ago•98 comments

MAUI Is Coming to Linux

https://avaloniaui.net/blog/maui-avalonia-preview-1
129•DeathArrow•7h ago•58 comments

Windows native app development is a mess

https://domenic.me/windows-native-dev/
290•domenicd•12h ago•318 comments

Theodosian Land Walls of Constantinople

https://turkisharchaeonews.net/object/theodosian-land-walls-constantinople
9•bcraven•3d ago•0 comments

Show HN: Codala, a social network built on scanning barcodes

https://play.google.com/store/apps/details?id=com.hsynkrkye.codala&hl=en
16•hsynkrkye•4d ago•7 comments

Building an FPGA 3dfx Voodoo with Modern RTL Tools

https://noquiche.fyi/voodoo
142•fayalalebrun•9h ago•31 comments

They're Vibe-Coding Spam Now

https://tedium.co/2026/02/25/vibe-coded-email-spam/
4•raybb•45m ago•1 comments

Palantir extends reach into British state as gets access to sensitive FCA data

https://www.theguardian.com/technology/2026/mar/22/palantir-extends-reach-into-british-state-as-i...
145•chrisjj•5h ago•43 comments

More common mistakes to avoid when creating system architecture diagrams

https://www.ilograph.com/blog/posts/more-common-diagram-mistakes/
127•billyp-rva•11h ago•50 comments

OpenClaw is a security nightmare dressed up as a daydream

https://composio.dev/content/openclaw-security-and-vulnerabilities
255•fs_software•5h ago•179 comments

Cloudflare flags archive.today as "C&C/Botnet"; no longer resolves via 1.1.1.2

https://radar.cloudflare.com/domains/domain/archive.today
349•winkelmann•19h ago•257 comments

How to Attract AI Bots to Your Open Source Project

https://nesbitt.io/2026/03/21/how-to-attract-ai-bots-to-your-open-source-project.html
40•zdw•1d ago•9 comments

Vectorization of Verilog Designs and its Effects on Verification and Synthesis

https://arxiv.org/abs/2603.17099
14•matt_d•3d ago•1 comments

Iran war energy crisis is a renewable energy wake-up call

https://apnews.com/article/middle-east-wars-renewable-energy-asia-4b5fe0693ce5816472c905db85f7da6e
14•mooreds•56m ago•0 comments

Why I love NixOS

https://www.birkey.co/2026-03-22-why-i-love-nixos.html
151•birkey•5h ago•117 comments

25 Years of Eggs

https://www.john-rush.com/posts/eggs-25-years-20260219.html
233•avyfain•4d ago•66 comments

Teaching Claude to QA a mobile app

https://christophermeiklejohn.com/ai/zabriskie/development/android/ios/2026/03/22/teaching-claude...
48•azhenley•3h ago•2 comments

The IBM scientist who rewrote the rules of information just won a Turing Award

https://www.ibm.com/think/news/ibm-scientist-charles-bennett-turing-award
84•rbanffy•11h ago•6 comments

A review of dice that came with the white castle

https://boardgamegeek.com/thread/3533812/a-review-of-dice-that-came-with-the-white-castle
120•doener•3d ago•36 comments

GrapheneOS refuses to comply with new age verification laws for operating system

https://www.tomshardware.com/software/operating-systems/grapheneos-refuses-to-comply-with-age-ver...
177•CrypticShift•6h ago•85 comments

Brute-forcing my algorithmic ignorance

http://blog.dominikrudnik.pl/my-google-recruitment-journey-part-1
88•qikcik•10h ago•53 comments