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.

Ageless Linux – Software for humans of indeterminate age

https://agelesslinux.org/
419•nateb2022•5h ago•271 comments

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

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

How Kernel Anti-Cheats Work: A Deep Dive into Modern Game Protection

https://s4dbrd.github.io/posts/how-kernel-anti-cheats-work/
62•davikr•3h ago•34 comments

Airbus is preparing two uncrewed combat aircraft

https://www.airbus.com/en/newsroom/press-releases/2026-03-airbus-is-preparing-two-uncrewed-combat...
86•phasnox•4h ago•43 comments

Tree Search Distillation for Language Models Using PPO

https://ayushtambde.com/blog/tree-search-distillation-for-language-models-using-ppo/
24•at2005•3h ago•0 comments

Mathematics Distillation Challenge – Equational Theories

https://terrytao.wordpress.com/2026/03/13/mathematics-distillation-challenge-equational-theories/
19•picafrost•18h ago•1 comments

Show HN: Han – A Korean programming language written in Rust

https://github.com/xodn348/han
118•xodn348•6h ago•78 comments

SBCL Fibers – Lightweight Cooperative Threads

https://atgreen.github.io/repl-yell/posts/sbcl-fibers/
48•anonzzzies•4h ago•4 comments

Bumblebee queens breathe underwater to survive drowning

https://www.smithsonianmag.com/science-nature/bumblebee-queens-breathe-underwater-to-survive-drow...
77•1659447091•7h ago•20 comments

Fedora 44 on the Raspberry Pi 5

https://nullr0ute.com/2026/03/fedora-44-on-the-raspberry-pi-5/
74•jandeboevrie•7h ago•21 comments

Launching the Claude Partner Network

https://www.anthropic.com/news/claude-partner-network
97•gmays•6h ago•46 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/
35•sebi_io•5h ago•3 comments

Learning Creative Coding

https://stigmollerhansen.dk/resume/learning-creative-coding/
52•ammerfest•5h ago•18 comments

Marketing for Founders

https://github.com/EdoStra/Marketing-for-Founders
131•jimsojim•8h ago•49 comments

Show HN: GrobPaint: Somewhere Between MS Paint and Paint.net

https://github.com/groverburger/grobpaint
26•__grob•5h ago•1 comments

Library of Short Stories

https://www.libraryofshortstories.com/
51•debo_•7h ago•1 comments

An ode to bzip

https://purplesyringa.moe/blog/an-ode-to-bzip/
104•signa11•11h ago•58 comments

A Recursive Algorithm to Render Signed Distance Fields

https://pointersgonewild.com/2026-03-06-a-recursive-algorithm-to-render-signed-distance-fields/
64•surprisetalk•3d ago•4 comments

Baochip-1x: What it is, why I'm doing it now and how it came about

https://www.crowdsupply.com/baochip/dabao/updates/what-it-is-why-im-doing-it-now-and-how-it-came-...
286•timhh•3d ago•55 comments

Montana passes Right to Compute act (2025)

https://www.westernmt.news/2025/04/21/montana-leads-the-nation-with-groundbreaking-right-to-compu...
252•bilsbie•13h ago•215 comments

Show HN: Ichinichi – One note per day, E2E encrypted, local-first

81•katspaugh•8h ago•27 comments

Postgres with Builtin File Systems

https://db9.ai/
47•ngaut•6h ago•12 comments

Changes to OpenTTD Distribution on Steam

https://www.openttd.org/news/2026/03/14/steam-changes
132•canpan•5h ago•89 comments

Python: The Optimization Ladder

https://cemrehancavdar.com/2026/03/10/optimization-ladder/
285•Twirrim•4d ago•104 comments

Refinement Modeling and Verification of RISC-V Assembly Using Knuckledragger

https://www.philipzucker.com/refine_assembly/
4•matt_d•3d ago•0 comments

Making Sense of the DXY

https://dm13450.github.io/2026/03/10/Making-Sense-of-the-DXY.html
5•dm13450•2d ago•2 comments

Starlink militarization and its impact on global strategic stability (2023)

https://interpret.csis.org/translations/starlink-militarization-and-its-impact-on-global-strategi...
142•msuniverse2026•18h ago•178 comments

1M context is now generally available for Opus 4.6 and Sonnet 4.6

https://claude.com/blog/1m-context-ga
1132•meetpateltech•1d ago•483 comments

Show HN: GitAgent – An open standard that turns any Git repo into an AI agent

https://www.gitagent.sh/
100•sivasurend•14h ago•14 comments

Megadev: A Development Kit for the Sega Mega Drive and Mega CD Hardware

https://github.com/drojaazu/megadev
119•XzetaU8•18h ago•7 comments