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

Comments

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

GrapheneOS – Break Free from Google and Apple

https://blog.tomaszdunia.pl/grapheneos-eng/
79•to3k•1h ago•44 comments

Is Show HN Dead? No, but It's Drowning

https://www.arthurcnops.blog/death-of-show-hn/
32•acnops•35m ago•19 comments

Four Column ASCII (2017)

https://garbagecollected.org/2017/01/31/four-column-ascii/
169•tempodox•2d ago•32 comments

14-year-old Miles Wu folded origami pattern that holds 10k times its own weight

https://www.smithsonianmag.com/innovation/this-14-year-old-is-using-origami-to-design-emergency-s...
703•bookofjoe•16h ago•143 comments

Rise of the Triforce

https://dolphin-emu.org/blog/2026/02/16/rise-of-the-triforce/
289•max-m•13h ago•33 comments

A deep dive into Apple's .car file format

https://dbg.re/posts/car-file-format/
95•MrFinch•2d ago•19 comments

Rendering the Visible Spectrum

https://brandonli.net/spectra/doc/
42•signa11•3d ago•4 comments

Poor Deming never stood a chance

https://surfingcomplexity.blog/2026/02/16/poor-deming-never-stood-a-chance/
81•todsacerdoti•8h ago•30 comments

What your Bluetooth devices reveal

https://blog.dmcc.io/journal/2026-bluetooth-privacy-bluehood/
439•ssgodderidge•20h ago•164 comments

Show HN: Glitchy camera – a circuit-bent camera simulator in the browser

https://glitchycam.com
27•elayabharath•23h ago•1 comments

Visual introduction to PyTorch

https://0byte.io/articles/pytorch_introduction.html
270•0bytematt•3d ago•20 comments

Evaluating AGENTS.md: are they helpful for coding agents?

https://arxiv.org/abs/2602.11988
128•mustaphah•22h ago•89 comments

Show HN: Free alternative to Wispr Flow, Superwhisper, and Monologue

https://github.com/zachlatta/freeflow
198•zachlatta•13h ago•93 comments

Dark web agent spotted bedroom wall clue to rescue girl from abuse

https://www.bbc.com/news/articles/cx2gn239exlo
436•colinprince•10h ago•233 comments

Xbox UI Portfolio Site

https://gabrielcabrera.co/
25•valgaze•5h ago•6 comments

Ghidra by NSA

https://github.com/NationalSecurityAgency/ghidra
378•handfuloflight•3d ago•195 comments

Show HN: Scanned 1927-1945 Daily USFS Work Diary

https://forestrydiary.com/
95•dogline•11h ago•16 comments

"Token anxiety", a slot machine by any other name

https://jkap.io/token-anxiety-or-a-slot-machine-by-any-other-name/
136•presbyterian•16h ago•116 comments

DBASE on the Kaypro II

https://stonetools.ghost.io/dbase-cpm/
52•TMWNN•3d ago•19 comments

Running NanoClaw in a Docker Shell Sandbox

https://www.docker.com/blog/run-nanoclaw-in-docker-shell-sandboxes/
114•four_fifths•12h ago•57 comments

State of Show HN: 2025

https://blog.sturdystatistics.com/posts/show_hn/
100•kianN•15h ago•22 comments

Neurons outside the brain

https://essays.debugyourpain.com/p/you-are-not-just-your-brain
102•yichab0d•16h ago•43 comments

Building for an audience of one: starting and finishing side projects with AI

https://codemade.net/blog/building-for-one/
70•lorisdev•11h ago•38 comments

Show HN: GitHub "Lines Viewed" extension to keep you sane reviewing long AI PRs

https://chromewebstore.google.com/detail/github-lines-viewed/npledcbofpmjjammgkkoeaehbphhdopi
15•somesortofthing•3d ago•17 comments

Show HN: Jemini – Gemini for the Epstein Files

https://jmail.world/jemini
380•dvrp•1d ago•73 comments

Show HN: Wildex – Pokémon Go for real wildlife

https://apps.apple.com/us/app/wildex-identify-plants-animals/id6748092158
84•AnujNayyar•13h ago•54 comments

Hear the "Amati King Cello", the Oldest Known Cello in Existence

https://www.openculture.com/2021/06/hear-the-amati-king-cello-the-oldest-known-cello-in-existence...
50•tesserato•4d ago•21 comments

SvarDOS – an open-source DOS distribution

http://svardos.org/
50•d_silin•4h ago•9 comments

WD and Seagate confirm: Hard drives sold out for 2026

https://www.heise.de/en/news/WD-and-Seagate-confirm-Hard-drives-for-2026-sold-out-11178917.html
89•layer8•1h ago•82 comments

PCB Rework and Repair Guide [pdf]

https://www.intertronics.co.uk/wp-content/uploads/2017/05/PCB-Rework-and-Repair-Guide.pdf
133•varjag•2d ago•37 comments