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

How NASA built Artemis II’s fault-tolerant computer

https://cacm.acm.org/news/how-nasa-built-artemis-iis-fault-tolerant-computer/
164•speckx•13h ago•53 comments

Native Instant Space Switching on macOS

https://arhan.sh/blog/native-instant-space-switching-on-macos/
372•PaulHoule•8h ago•186 comments

We've raised $17M to build what comes after Git

https://blog.gitbutler.com/series-a
28•ellieh•2h ago•29 comments

Generative art over the years

https://blog.veitheller.de/Generative_art_over_the_years.html
49•evakhoury•2d ago•16 comments

Apple's New iPhone Update Is Restricting Internet Freedom in the UK

https://bigbrotherwatch.org.uk/blog/apples-new-iphone-update-is-restricting-internet-freedom-in-t...
65•josephcsible•3h ago•28 comments

RAM Has a Design Flaw from 1966. I Bypassed It [video]

https://www.youtube.com/watch?v=KKbgulTp3FE
77•surprisetalk•2d ago•5 comments

Charcuterie – Visual similarity Unicode explorer

https://charcuterie.elastiq.ch/
163•rickcarlino•8h ago•28 comments

PicoZ80 – Drop-In Z80 Replacement

https://eaw.app/picoz80/
165•rickcarlino•9h ago•28 comments

The Raft Consensus Algorithm Explained Through "Mean Girls"

https://www.cockroachlabs.com/blog/raft-is-so-fetch/
4•vermilingua•1h ago•0 comments

Reverse engineering Gemini's SynthID detection

https://github.com/aloshdenny/reverse-SynthID
121•_tk_•8h ago•45 comments

Unfolder for Mac – A 3D model unfolding tool for creating papercraft

https://www.unfolder.app/
169•codazoda•11h ago•34 comments

Moving from WordPress to Jekyll (and static site generators in general)

https://www.demandsphere.com/blog/rebuilding-demandsphere-with-jekyll-and-claude-code/
58•rgrieselhuber•7h ago•27 comments

Principles of Mechanical Sympathy

https://martinfowler.com/articles/mechanical-sympathy-principles.html
8•zdw•2d ago•0 comments

Research-Driven Agents: When an agent reads before it codes

https://blog.skypilot.co/research-driven-agents/
148•hopechong•11h ago•48 comments

Top laptops to use with FreeBSD

https://freebsdfoundation.github.io/freebsd-laptop-testing/
300•fork-bomber•19h ago•169 comments

Hegel, a universal property-based testing protocol and family of PBT libraries

https://hegel.dev
91•PaulHoule•9h ago•30 comments

Many African families spend fortunes burying their dead

https://davidoks.blog/p/how-funerals-keep-africa-poor
159•powera•6h ago•138 comments

Reallocating $100/Month Claude Code Spend to Zed and OpenRouter

https://braw.dev/blog/2026-04-06-reallocating-100-month-claude-spend/
316•kisamoto•19h ago•208 comments

Old laptops in a colo as low cost servers

https://colaptop.pages.dev/
178•argentum47•9h ago•100 comments

How Close Is Too Close? Applying Fluid Dynamics Research Methods to PC Cooling

https://www.lttlabs.com/articles/2026/04/04/how-close-is-too-close-applying-fundamental-fluid-dyn...
21•LabsLucas•4d ago•4 comments

Microsoft PhotoDNA scanning problem

https://www.elevenforum.com/t/microsoft-photodna-scanning-problem-it-is-comical-now.45961/
89•darkzek•3h ago•36 comments

Show HN: I built a Cargo-like build tool for C/C++

https://github.com/randerson112/craft
130•randerson_112•12h ago•113 comments

A WebGPU implementation of Augmented Vertex Block Descent

https://github.com/jure/webphysics
132•juretriglav•16h ago•15 comments

Show HN: Druids – Build your own software factory

https://github.com/fulcrumresearch/druids
35•etherio•1d ago•6 comments

EFF is leaving X

https://www.eff.org/deeplinks/2026/04/eff-leaving-x
1203•gregsadetsky•11h ago•1020 comments

Microsoft is employing dark patterns to goad users into paying for storage?

https://lzon.ca/posts/other/microsoft-user-abuse/
258•jpmitchell•7h ago•142 comments

LittleSnitch for Linux

https://obdev.at/products/littlesnitch-linux/index.html
1284•pluc•1d ago•418 comments

The Training Example Lie Bracket

https://pbement.com/posts/lie_brackets/
23•pb1729•6h ago•11 comments

Launch HN: Relvy (YC F24) – On-call runbooks, automated

https://www.relvy.ai
41•behat•16h ago•22 comments

Haunted Paper Toys

http://ravensblight.com/papertoys.html
233•exvi•3d ago•29 comments