frontpage.
newsnewestaskshowjobs

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•1y ago

Comments

LegionMammal978•1y 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•1y 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•1y 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.

KOReader

https://koreader.rocks/
26•Cider9986•1h ago•2 comments

More Tailscale tricks for your jailbroken Kindle

https://tailscale.com/blog/jailbroken-kindle-proxy-tun-modes
248•Error6571•7h ago•84 comments

National Security Determination Threat Posed by Foreign-Produced Robotic Devices [pdf]

https://www.fcc.gov/sites/default/files/robots-nsd.pdf
35•ellingsworth•1h ago•34 comments

Amiga Graphics Archive

https://amiga.lychesis.net/index.html
33•Bluestein•1h ago•5 comments

SpecForge – A Platform for Authoring Formal Specifications

https://docs.imiron.io/v/0.5.10/en/tour.html
25•agnishom•1h ago•1 comments

Document-borne AI worms can self-propagate through Copilot for Word

https://enklypesalt.com/posts/context-collapse-part3-ai-worming-through-word/
10•Canopy9560•21m ago•3 comments

User Interfaces of the Demo Scene

https://www.datagubbe.se/scenegui/
251•zdw•7h ago•40 comments

SQLite in Production: Optimizing WAL Mode, Concurrency, and VFS Layers

https://micrologics.org/blog/sqlite-in-production-optimizing-wal-mode-concurrency-and-vfs-layers-...
99•ankitg12•4h ago•40 comments

Lisp moving Forth moving Lisp

https://letoverlambda.com/textmode.cl/guest/chap8.html
46•fallat•2d ago•16 comments

Codex Security

https://github.com/openai/codex-security
525•bakigul•15h ago•190 comments

They Stole Your Attention

https://moai.studio/blog/posts/they-stole-your-attention.html
8•ionwake•38m ago•3 comments

Show HN: I was tired of opening 2 tabs for every HN link, so I made a userscript

https://github.com/twalichiewicz/HNewhere
336•twalichiewicz•13h ago•100 comments

Ancient Rome's version of Google Maps: how long to reach the beach

https://www.euronews.com/culture/2026/07/02/ancient-romes-version-of-google-maps-how-long-to-reac...
28•gnabgib•6d ago•21 comments

Substack writers, you need a website

https://elizabethtai.com/2026/06/10/substack-writers-you-need-a-website/
569•speckx•19h ago•304 comments

Half-Life ported to Mac OS 9

https://mac-classic.com/news/half-life-ported-to-mac-os-9/
262•freediver•15h ago•125 comments

Show HN: Vimgolf.ai – Learn Vim by playing through a map of levels

https://vimgolf.ai
13•nickandbro•2h ago•8 comments

Starling: The first real desktop written by AI

https://starling.build/
7•signa11•1h ago•1 comments

Kimi K3 Architecture Overview and Notes

https://sebastianraschka.com/blog/2026/kimi-k3-architecture-notes.html
454•ModelForge•20h ago•98 comments

We Hardened an AI Security Platform Against 16 Critical Vulnerabilities

https://aegis-security.higgsfield.app
6•zdotbirch•1h ago•0 comments

LearnVector – Andrew Ng's AI company building one‑to‑one learning experiences

https://learnvector.ai/
217•ajhai•10h ago•134 comments

ReFrame – The EPaper Camera

https://reframe.camera/
155•phil294•12h ago•33 comments

Cracking Windows Open: Porting RADV to Win32

https://www.collabora.com/news-and-blog/news-and-events/cracking-windows-open-porting-radv-to-win...
56•zdw•7h ago•19 comments

Steel Bank Common Lisp version 2.6.7

https://sbcl.org/all-news.html?2.6.7
247•tmtvl•18h ago•114 comments

Hubble: Open-source notetaking app for you and your agents

https://www.hubble.md/
126•handfuloflight•11h ago•57 comments

Teach yourself programming in ten years (1998)

https://www.norvig.com/21-days.html
162•vinhnx•3d ago•95 comments

Delayed Gratification – Proud to Be 'Last to Breaking News'

https://www.slow-journalism.com/
309•speerer•20h ago•176 comments

60 Years Ago, a Submerged Submarine Circled the Globe for the First Time (2020)

https://www.popularmechanics.com/military/weapons/a32009109/operation-sandblast-sumbarine-circumn...
27•baud147258•1d ago•9 comments

Transformer Transformer: A Unified Model for Motion-Conditioned Robot Co-Design

https://transformer-transformer.github.io/
57•ilreb•8h ago•6 comments

Hooray for the Sockets Interface

https://blog.apnic.net/2026/07/28/hooray-for-the-sockets-interface/
45•jruohonen•9h ago•26 comments

Una GPS smart watch – Repairable, USB-C charging, developer-friendly

https://unawatch.com/
238•pimterry•21h ago•146 comments