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

What makes Intel Optane stand out (2023)

https://blog.zuthof.nl/2023/06/02/what-makes-intel-optane-stand-out/
111•walterbell•4h ago•84 comments

Separating the Wayland compositor and window manager

https://isaacfreund.com/blog/river-window-management/
87•dpassens•4h ago•40 comments

Glassworm Is Back: A New Wave of Invisible Unicode Attacks Hits Repositories

https://www.aikido.dev/blog/glassworm-returns-unicode-attack-github-npm-vscode
129•robinhouston•6h ago•66 comments

C++26: The Oxford Variadic Comma

https://www.sandordargo.com/blog/2026/03/11/cpp26-oxford-variadic-comma
39•ingve•4d ago•16 comments

In Memoriam: John W. Addison, my PhD advisor

https://billwadge.com/2026/03/15/in-memoriam-john-w-addison-jr-my-phd-advisor/
26•herodotus•3h ago•2 comments

A Visual Introduction to Machine Learning (2015)

https://r2d3.us/visual-intro-to-machine-learning-part-1/
259•vismit2000•8h ago•23 comments

Show HN: GDSL – 800 line kernel: Lisp subset in 500, C subset in 1300

https://firthemouse.github.io/
33•FirTheMouse•3h ago•5 comments

Learning athletic humanoid tennis skills from imperfect human motion data

https://zzk273.github.io/LATENT/
44•danielmorozoff•3h ago•4 comments

Hollywood Enters Oscars Weekend in Existential Crisis

https://www.theculturenewspaper.com/hollywood-enters-oscars-weekend-in-existential-crisis/
67•RickJWagner•6h ago•185 comments

Rack-mount hydroponics

https://sa.lj.am/rack-mount-hydroponics/
311•cdrnsf•14h ago•82 comments

Show HN: Signet – Autonomous wildfire tracking from satellite and weather data

https://signet.watch
87•mapldx•7h ago•25 comments

Show HN: What if your synthesizer was powered by APL (or a dumb K clone)?

https://octetta.github.io/k-synth/
52•octetta•6h ago•27 comments

Grandparents are glued to their phones, families are worried [video]

https://www.bbc.com/reel/video/p0n61dg3/grandparents-are-glued-to-their-phones-families-are-worried
97•tartoran•1h ago•52 comments

Bus travel from Lima to Rio de Janeiro

https://kenschutte.com/lima-to-rio-by-bus/
5•ks2048•4d ago•0 comments

LLM Architecture Gallery

https://sebastianraschka.com/llm-architecture-gallery/
7•tzury•3h ago•1 comments

Kniterate Notes

https://soup.agnescameron.info//2026/03/07/kniterate-notes.html
41•surprisetalk•5d ago•10 comments

Autoresearch Hub

http://autoresearchhub.com/
3•EvgeniyZh•1d ago•1 comments

IBM, sonic delay lines, and the history of the 80×24 display (2019)

https://www.righto.com/2019/11/ibm-sonic-delay-lines-and-history-of.html
59•rbanffy•8h ago•13 comments

$96 3D-printed rocket that recalculates its mid-air trajectory using a $5 sensor

https://github.com/novatic14/MANPADS-System-Launcher-and-Rocket
316•ZacnyLos•8h ago•280 comments

Generating All 32-Bit Primes (Part I)

https://hnlyman.github.io/pages/prime32_I.html
64•hnlyman•7h ago•19 comments

Office.eu launches as Europe's sovereign office platform

https://office.eu/media/pressrelease-20260304
91•campuscodi•48m ago•58 comments

How kernel anti-cheats work

https://s4dbrd.github.io/posts/how-kernel-anti-cheats-work/
319•davikr•18h ago•274 comments

The 100 hour gap between a vibecoded prototype and a working product

https://kanfa.macbudkowski.com/vibecoding-cryptosaurus
182•kiwieater•7h ago•233 comments

A most elegant TCP hole punching algorithm

https://robertsdotpm.github.io/cryptography/tcp_hole_punching.html
188•Uptrenda•15h ago•76 comments

Zipp 2001 Restoration

https://robot-daycare.com/posts/zipp-2001-restoration-part-1/
17•o4c•4d ago•0 comments

Why Mathematica does not simplify sinh(arccosh(x))

https://www.johndcook.com/blog/2026/03/10/sinh-arccosh/
129•ibobev•4d ago•48 comments

Treasure hunter freed from jail after refusing to turn over shipwreck gold

https://www.bbc.com/news/articles/cg4g7kn99q3o
156•tartoran•16h ago•212 comments

UMD Scientists Create 'Smart Underwear' to Measure Human Flatulence

https://cbmg.umd.edu/news-events/news/brantley-hall-umd-scientists-create-smart-underwear-measure...
65•ohjeez•3h ago•40 comments

Allow me to get to know you, mistakes and all

https://sebi.io/posts/2026-03-14-allow-me-to-get-to-know-you-mistakes-and-all/
275•sebi_io•21h ago•130 comments

Human Organ Atlas

https://www.science.org/doi/10.1126/sciadv.adz2240
65•bookofjoe•3d ago•4 comments