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.

Do Not Turn Child Protection into Internet Access Control

https://news.dyne.org/child-protection-is-not-access-control/
257•smartmic•2h ago•95 comments

Tinybox- offline AI device 120B parameters

https://tinygrad.org/#tinybox
205•albelfio•3h ago•119 comments

Some things just take time

https://lucumr.pocoo.org/2026/3/20/some-things-just-take-time/
440•vaylian•8h ago•147 comments

Professional video editing, right in the browser with WebGPU and WASM

https://tooscut.app/
43•mohebifar•1h ago•12 comments

Show HN: Termcraft – terminal-first 2D sandbox survival in Rust

https://github.com/pagel-s/termcraft
66•sebosch•4h ago•6 comments

Grafeo – A fast, lean, embeddable graph database built in Rust

https://grafeo.dev/
164•0x1997•8h ago•55 comments

Electronics for Kids, 2nd Edition

https://nostarch.com/electronics-for-kids-2e
56•0x54MUR41•2d ago•7 comments

The seven hour explosion nobody could explain

https://phys.org/news/2026-03-hour-explosion.html
77•mellosouls•4d ago•9 comments

How Invisalign became the biggest user of 3D printers

https://www.wired.com/story/how-invisalign-became-the-worlds-biggest-3d-printing-company/
116•mikhael•2d ago•83 comments

No Semicolons Needed

https://terts.dev/blog/no-semicolons-needed/
26•karakoram•4h ago•22 comments

No evidence cannabis helps anxiety, depression, or PTSD

https://www.sciencedaily.com/releases/2026/03/260319044656.htm
111•nothrowaways•3h ago•86 comments

The paddle wheel aircraft carriers of Lake Michigan

https://signoregalilei.com/2026/03/08/the-paddle-wheel-aircraft-carriers-of-lake-michigan/
24•surprisetalk•4d ago•3 comments

Common Lisp Development Tooling

https://www.creativetension.co/posts/common-lisp-development-tooling
21•0bytematt•3h ago•2 comments

Hide macOS Tahoe's Menu Icons

https://512pixels.net/2026/03/hide-macos-tahoes-menu-icons-with-this-one-simple-trick/
62•soheilpro•5h ago•17 comments

ZJIT removes redundant object loads and stores

https://railsatscale.com/2026-03-18-how-zjit-removes-redundant-object-loads-and-stores/
67•tekknolagi•3d ago•10 comments

Attempts to post the latest Trivy security incident have been marked [dead]

https://news.ycombinator.com/from?site=github.com%2Faquasecurity
5•JoshuaDavid•1h ago•3 comments

Floci – A free, open-source local AWS emulator

https://github.com/hectorvent/floci
3•shaicoleman•1h ago•0 comments

Ubuntu 26.04 Ends 46 Years of Silent sudo Passwords

https://pbxscience.com/ubuntu-26-04-ends-46-years-of-silent-sudo-passwords/
294•akersten•18h ago•299 comments

Show HN: Atomic – self-hosted, semantically-connected personal knowledge base

https://github.com/kenforthewin/atomic
28•kenforthewin•3h ago•2 comments

Thinking Fast, Slow, and Artificial: How AI Is Reshaping Human Reasoning

https://papers.ssrn.com/sol3/papers.cfm?abstract_id=6097646
77•Anon84•7h ago•47 comments

Meta's Omnilingual MT for 1,600 Languages

https://ai.meta.com/research/publications/omnilingual-mt-machine-translation-for-1600-languages/?...
110•j0e1•3d ago•31 comments

Hawaii's worst flooding in 20 years threatens dam, prompts evacuations

https://www.nbcnews.com/weather/floods/hawaii-worst-flooding-in-20-years-rcna264573
46•geox•3h ago•14 comments

Esqueleto Tutorial

https://entropicthoughts.com/esqueleto-tutorial
7•ibobev•4d ago•0 comments

A Japanese glossary of chopsticks faux pas (2022)

https://www.nippon.com/en/japan-data/h01362/
447•cainxinth•1d ago•346 comments

Mamba-3

https://www.together.ai/blog/mamba-3
269•matt_d•4d ago•50 comments

Books of the Century by Le Monde

https://standardebooks.org/collections/le-mondes-100-books-of-the-century
87•zlu•2d ago•56 comments

Show HN: Joonote – A note-taking app on your lock screen and notification panel

https://joonote.com/
33•kilgarenone•8h ago•27 comments

FFmpeg 101 (2024)

https://blogs.igalia.com/llepage/ffmpeg-101/
205•vinhnx•20h ago•8 comments

Blocking Internet Archive Won't Stop AI, but Will Erase Web's Historical Record

https://www.eff.org/deeplinks/2026/03/blocking-internet-archive-wont-stop-ai-it-will-erase-webs-h...
475•pabs3•15h ago•131 comments

OpenCode – Open source AI coding agent

https://opencode.ai/
1184•rbanffy•1d ago•580 comments