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.

An entire Herculaneum scroll has been read for the first time

https://scrollprize.org/firstscroll
863•verditelabs•7h ago•198 comments

The 'papers, please' era of the internet will decimate your privacy

https://expression.fire.org/p/the-papers-please-era-of-the-internet
239•bilsbie•2h ago•98 comments

Un-0: Generating Images with Coupled Oscillators

https://unconv.ai/blog/introducing-un-0-generating-images-with-coupled-oscillators/
82•babelfish•2h ago•11 comments

Oxide computer 3D rack guided tour

https://explorer.oxide.computer/
269•darthcloud•3d ago•112 comments

IBM debuts sub-1 nanometer chip technology

https://newsroom.ibm.com/2026-06-25-ibm-debuts-worlds-first-sub-1-nanometer-chip-technology
247•porridgeraisin•8h ago•143 comments

An oral history of Bank Python (2021)

https://calpaterson.com/bank-python.html
52•tosh•3h ago•12 comments

A game where you're an OS and have to manage processes, memory and I/O events

https://github.com/plbrault/youre-the-os
52•exploraz•2d ago•12 comments

Show HN: OpenKnowledge – open source AI-first alternative to Obsidian/Notion

https://github.com/inkeep/open-knowledge
171•engomez•7h ago•77 comments

Parallel Parentheses Matching

https://williamdue.github.io/blog/parallel-parentheses-matching
41•Athas•3h ago•7 comments

Om Malik has died

https://om.co/2026/06/24/1966-2026/
269•minimaxir•3h ago•29 comments

Migrating from Proxmox to NixOS and Incus

https://www.nijho.lt/post/proxmox-to-nixos/
28•wasting_time•2h ago•13 comments

Show HN: Chess-Inspired Roguelike

https://princechazz.com
191•cowboy_henk•4d ago•67 comments

Zig's new bitCast semantics and LLVM back end improvements

https://ziglang.org/devlog/2026/#2026-06-25
206•kouosi•9h ago•79 comments

The Doorman's Fallacy in action

https://rozumem.xyz/posts/17
36•rozumem•3h ago•56 comments

OS9Map

https://yllan.org/software/OS9Map/
168•LaSombra•8h ago•25 comments

Apple raises prices of MacBooks, iPads

https://www.reuters.com/world/asia-pacific/apple-raises-prices-macbooks-ipads-memory-costs-skyroc...
592•virgildotcodes•10h ago•844 comments

The last Romans are still around

https://signoregalilei.com/2026/06/20/the-last-romans-are-still-around/
27•surprisetalk•3d ago•48 comments

The annotated PyTorch training loop

https://idlemachines.co.uk/essays/pytorch-training-loop
50•smaddrellmander•3d ago•9 comments

You can't unit test for taste

https://dev.karltryggvason.com/you-cant-unit-test-for-taste/
237•kalli•1d ago•113 comments

Besimple AI (YC P25) Is Hiring

https://www.ycombinator.com/companies/besimple-ai/jobs/yWfhhOR-strategic-projects-lead-audio-data
1•yzhong94•6h ago

GloriousEggroll's Proton has been rebased on Proton 11

https://github.com/GloriousEggroll/proton-ge-custom/releases/tag/GE-Proton11-1
46•d3Xt3r•1d ago•13 comments

Military branches restore flu shot requirement after virus swept through base

https://arstechnica.com/health/2026/06/military-branches-restore-flu-shot-requirement-after-virus...
45•tzs•1h ago•19 comments

RRB-Trees: Efficient Immutable Vectors (2012) [pdf]

https://infoscience.epfl.ch/server/api/core/bitstreams/e5d662ea-1e8d-4dda-b917-8cbb8bb40bf9/content
31•azhenley•1d ago•7 comments

OpenAI Leans Toward Waiting Until Next Year for IPO

https://www.nytimes.com/2026/06/25/technology/openai-ipo-artificial-intelligence.html
81•mfiguiere•3h ago•53 comments

Advanced Nintendo Entertainment System (ANES) – NES Modded to Use 2 PPUs

https://github.com/decrazyo/anes
91•zdw•2d ago•30 comments

Show HN: I made Google Trends for Hacker News by indexing 18 years of comments

https://hackernewstrends.com
632•ytkimirti•9h ago•143 comments

The disappearance of Japan's animators

https://economist.com/interactive/1843/2026/06/19/the-strange-disappearance-of-japans-animators
132•andsoitis•4d ago•107 comments

Political bias in AI: Where the AI models stand

https://trakkr.ai/bias
102•mektrik•10h ago•208 comments

Tw-fade: pure CSS scroll-driven edge masking

https://pete.design/tw-fade
83•petekp•3d ago•30 comments

I built a GPU back end for Emacs

https://en.andros.dev/blog/4b707a03/how-i-built-a-gpu-backend-for-emacs/
167•andros•2d ago•84 comments