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.

I Fixed Windows Native Development

https://marler8997.github.io/blog/fixed-windows/
271•deevus•4h ago•123 comments

AI is going to kill app subscriptions

https://nichehunt.app/blog/ai-going-to-kill-app-subscriptions
30•informal007•25m ago•27 comments

I love the work of the ArchWiki maintainers

https://k7r.eu/i-love-the-work-of-the-archwiki-maintainers/
689•panic•14h ago•116 comments

Amazon, Google Unwittingly Reveal the Severity of the U.S. Surveillance State

https://greenwald.substack.com/p/amazons-ring-and-googles-nest-unwittingly
231•mikece•3h ago•117 comments

Flashpoint Archive – Over 200k web games and animations preserved

https://flashpointarchive.org
222•helloplanets•10h ago•51 comments

Reversed engineered game Starflight (1986)

https://github.com/s-macke/starflight-reverse
35•tosh•4h ago•11 comments

How Is Data Stored?

https://www.makingsoftware.com/chapters/how-is-data-stored
23•tzury•5d ago•0 comments

RynnBrain

https://github.com/alibaba-damo-academy/RynnBrain
28•jsemrau•4d ago•0 comments

My smart sleep mask broadcasts users' brainwaves to an open MQTT broker

https://aimilios.bearblog.dev/reverse-engineering-sleep-mask/
526•minimalthinker•1d ago•229 comments

Oat – Ultra-lightweight, semantic, zero-dependency HTML UI component library

https://oat.ink/
226•twapi•7h ago•64 comments

A practical guide to observing the night sky for real skies and real equipment

https://stargazingbuddy.com/
76•constantinum•2d ago•9 comments

Constraint Propagation for Fun

https://eli.li/constraint-propagation-for-fun
28•rickcarlino•5d ago•0 comments

A Pokémon of a Different Color

https://matthew.verive.me/blog/color/
36•Risse•5h ago•6 comments

Zvec: A lightweight, fast, in-process vector database

https://github.com/alibaba/zvec
187•dvrp•2d ago•35 comments

Interference Pattern Formed in a Finger Gap Is Not Single Slit Diffraction

https://note.com/hydraenids/n/nbe89030deaba
70•uolmir•2d ago•11 comments

The Dark Side of the Enlightenment

https://www.newstatesman.com/culture/books/2026/02/the-dark-side-of-the-enlightenment
17•thinkingemote•1h ago•6 comments

Instagram's URL Blackhole

https://medium.com/@shredlife/instagrams-url-blackhole-c1733e081664
261•tkp-415•1d ago•43 comments

Build Gaussian Splat Experiences with SuperSplat Studio

https://blog.playcanvas.com/build-gaussian-splat-experiences-with-supersplat-studio/
4•ovenchips•3d ago•0 comments

uBlock filter list to hide all YouTube Shorts

https://github.com/i5heu/ublock-hide-yt-shorts/
1021•i5heu•22h ago•302 comments

Kimi Claw

https://www.kimi.com/bot
50•pretext•1h ago•49 comments

DjVu and its connection to Deep Learning (2023)

https://scottlocklin.wordpress.com/2023/05/31/djvu-and-its-connection-to-deep-learning/
28•tosh•6h ago•3 comments

5,300-year-old 'bow drill' rewrites story of ancient Egyptian tools

https://www.ncl.ac.uk/press/articles/latest/2026/02/ancientegyptiandrillbit/
145•geox•4d ago•52 comments

Two different tricks for fast LLM inference

https://www.seangoedecke.com/fast-llm-inference/
94•swah•6h ago•44 comments

Guitars of the USSR and the Jolana Special in Azerbaijani Music (2012)

https://caucascapades.wordpress.com/2012/06/14/guitars-of-the-ussr-and-the-jolana-special-in-azer...
75•bpierre•12h ago•10 comments

Show HN: Copy-and-patch compiler for hard real-time Python

https://github.com/Nonannet/copapy
35•Saloc•4d ago•2 comments

OpenAI should build Slack

https://www.latent.space/p/ainews-why-openai-should-build-slack
212•swyx•1d ago•252 comments

Amsterdam Compiler Kit

https://github.com/davidgiven/ack
146•andsoitis•22h ago•50 comments

News publishers limit Internet Archive access due to AI scraping concerns

https://www.niemanlab.org/2026/01/news-publishers-limit-internet-archive-access-due-to-ai-scrapin...
531•ninjagoo•20h ago•333 comments

A Visual Source for Shakespeare's 'Tempest'

https://profadamroberts.substack.com/p/a-visual-source-for-shakespeares
23•seegodanddie•3d ago•1 comments

Breaking the spell of vibe coding

https://www.fast.ai/posts/2026-01-28-dark-flow/
345•arjunbanker•1d ago•260 comments