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

Comments

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

Search tool that only returns content created before ChatGPT's public release

https://tegabrain.com/Slop-Evader
41•dmitrygr•1h ago•12 comments

'A full-blown crisis': Americans brace for a surge in healthcare costs

https://www.ft.com/content/beec76df-8e6d-4238-bae2-e51683b62aa4
31•mmarian•28m ago•20 comments

A Love Letter to FreeBSD

https://www.tara.sh/posts/2025/2025-11-25_freebsd_letter/
242•rbanffy•7h ago•140 comments

Advent of Sysadmin 2025

https://sadservers.com/advent
108•lazyant•4h ago•29 comments

Advent of Code 2025

https://adventofcode.com/2025/about
793•vismit2000•16h ago•274 comments

Algorithms for Optimization [pdf]

https://algorithmsbook.com/optimization/files/optimization.pdf
176•Anon84•5h ago•13 comments

Writing a good Claude.md

https://www.humanlayer.dev/blog/writing-a-good-claude-md
412•objcts•11h ago•123 comments

X210Ai is a new motherboard to upgrade ThinkPad X201/200

https://www.tpart.net/about-x210ai/
16•walterbell•2h ago•2 comments

Windows drive letters are not limited to A-Z

https://www.ryanliptak.com/blog/windows-drive-letters-are-not-limited-to-a-z/
402•LorenDB•15h ago•204 comments

Bricklink suspends Marketplace operations in 35 countries

https://jaysbrickblog.com/news/bricklink-suspends-marketplace-operations-in-35-countries/
93•makeitdouble•6h ago•40 comments

Migrating Dillo from GitHub

https://dillo-browser.org/news/migration-from-github/
309•todsacerdoti•15h ago•171 comments

Is America's jobs market nearing a cliff?

https://www.economist.com/finance-and-economics/2025/11/30/is-americas-jobs-market-nearing-a-cliff
117•harambae•4h ago•190 comments

Replacing My Window Manager with Google Chrome

https://foxmoss.com/blog/dote/
15•foxmoss•3d ago•5 comments

GitHub to Codeberg: my experience

https://eldred.fr/blog/forge-migration/
193•todsacerdoti•13h ago•72 comments

LLVM-MOS – Clang LLVM fork targeting the 6502

https://llvm-mos.org/wiki/Welcome
118•jdmoreira•12h ago•48 comments

Seeing a Molecule's Quantum Shadow

https://physics.aps.org/articles/v18/s149
13•lc0_stein•6d ago•1 comments

Program-of-Thought Prompting Outperforms Chain-of-Thought by 15% (2022)

https://arxiv.org/abs/2211.12588
96•mkagenius•10h ago•26 comments

ESA Sentinel-1D delivers first high-resolution images

https://www.esa.int/Applications/Observing_the_Earth/Copernicus/Sentinel-1/Sentinel-1D_delivers_f...
88•giuliomagnifico•11h ago•28 comments

ETH-Zurich: Digital Design and Computer Architecture; 227-0003-10L, Spring, 2025

https://safari.ethz.ch/ddca/spring2025/doku.php?id=start
133•__rito__•11h ago•17 comments

How to run phones while being struck by suicide drones

https://nasa.cx/hn/posts/how-to-run-hundreds-of-phones-while-being-struck-by-suicide-drones/
64•nasaok•8h ago•17 comments

Show HN: A "Cram tests" script for windows shells

https://github.com/NyuB/craw
3•NyuB•4d ago•0 comments

AI just proved Erdos Problem #124

https://www.erdosproblems.com/forum/thread/124#post-1892
144•nl•1d ago•42 comments

Stereo Images of Giant Galaxies

https://www.bbc.com/future/article/20251121-sir-brian-mays-stereo-vision-of-galaxies
25•benbreen•6d ago•10 comments

Show HN: Fixing Google Nano Banana Pixel Art with Rust

https://github.com/Hugo-Dz/spritefusion-pixel-snapper
142•HugoDz•4d ago•23 comments

The Thinking Game Film – Google DeepMind documentary

https://thinkinggamefilm.com
165•ChrisArchitect•13h ago•113 comments

“Boobs check” – Technique to verify if sites behind CDN are hosted in Iran

https://twitter.com/hkashfi/status/1995109785679573167
258•defly•8h ago•82 comments

Hacking on the ReMarkable 2

https://sgt.hootr.club/blog/hacking-on-the-remarkable-2/
30•todsacerdoti•9h ago•4 comments

There is No Quintic Formula [video]

https://www.youtube.com/watch?v=9HIy5dJE-zQ
73•DamnInteresting•11h ago•30 comments

Paul Hegarty's updated CS193p SwiftUI course released by Stanford

https://cs193p.stanford.edu/
166•yehiaabdelm•5d ago•35 comments

RetailReady (YC W24) Is Hiring Associate Product Manager

https://www.ycombinator.com/companies/retailready/jobs/KPKDu3D-associate-product-manager
1•sarah74•12h ago