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.

Tell HN: Anthropic no longer allowing Claude Code subscriptions to use OpenClaw

678•firloop•10h ago•559 comments

Artemis II crew take “spectacular” image of Earth

https://www.bbc.com/news/articles/ce8jzr423p9o
761•andsoitis•14h ago•267 comments

Some Unusual Trees

https://thoughts.wyounas.com/p/some-unusual-trees
9•simplegeek•49m ago•1 comments

iNaturalist

https://www.inaturalist.org/
424•bookofjoe•16h ago•108 comments

OpenClaw privilege escalation vulnerability

https://nvd.nist.gov/vuln/detail/CVE-2026-33579
366•kykeonaut•17h ago•194 comments

Delve removed from Y Combinator

https://www.ycombinator.com/companies/delve
295•carabiner•8h ago•182 comments

Herbie: Automatically improve imprecise floating point formulas

https://herbie.uwplse.org/doc/latest/tutorial.html
120•summarity•3d ago•15 comments

Run Linux containers on Android, no root required

https://github.com/ExTV/Podroid
122•politelemon•11h ago•41 comments

What changes when you turn a Linux box into a router

https://patrickmccanna.net/7-configuration-changes-that-turn-a-multi-homed-host-into-a-switch-rou...
177•0o_MrPatrick_o0•3d ago•44 comments

Improving my focus by giving up my big monitor

https://ounapuu.ee/posts/2026/04/01/focus/
93•Fudgel•3d ago•106 comments

Post Mortem: axios NPM supply chain compromise

https://github.com/axios/axios/issues/10636
255•Kyro38•1d ago•116 comments

We replaced RAG with a virtual filesystem for our AI documentation assistant

https://www.mintlify.com/blog/how-we-built-a-virtual-filesystem-for-our-assistant
306•denssumesh•1d ago•118 comments

Gold overtakes U.S. Treasuries as the largest foreign reserve asset

https://economictimes.indiatimes.com/news/international/us/gold-overtakes-u-s-treasuries-as-the-w...
185•lxm•7h ago•129 comments

Sequential Optimal Packing for PCB Placement

https://blog.autorouting.com/p/sequential-optimal-packing-for-pcb
9•seveibar•2d ago•1 comments

The Technocracy Movement of the 1930s

https://donotresearch.substack.com/p/welcome-to-the-technocracy
99•lazydogbrownfox•1d ago•84 comments

Go on Embedded Systems and WebAssembly

https://tinygo.org/
160•uticus•16h ago•21 comments

Remembering Magnetic Memories and the Apollo AGC

https://2earth.github.io/website/20260304.html
15•2earth•3d ago•3 comments

Show HN: Travel Hacking Toolkit – Points search and trip planning with AI

https://github.com/borski/travel-hacking-toolkit
70•borski•7h ago•31 comments

The house is a work of art: Frank Lloyd Wright

https://aeon.co/essays/frank-lloyd-wright-as-a-mirror-of-the-american-condition
84•midnightfish•11h ago•38 comments

How to make a sliding, self-locking, and predator-proof chicken coop door (2020)

https://www.backyardchickens.com/articles/how-to-make-a-sliding-self-locking-and-predator-proof-c...
105•uticus•14h ago•46 comments

Big-Endian Testing with QEMU

https://www.hanshq.net/big-endian-qemu.html
93•jandeboevrie•20h ago•102 comments

F-15E jet shot down over Iran

https://www.theguardian.com/world/2026/apr/03/us-fighter-jet-confirmed-shot-down-over-iran
486•tjwds•17h ago•1090 comments

Emotion concepts and their function in a large language model

https://www.anthropic.com/research/emotion-concepts-function
53•dnw•3h ago•41 comments

Build your own Dial-up ISP with a Raspberry Pi

https://www.jeffgeerling.com/blog/2026/build-your-own-dial-up-isp-with-a-raspberry-pi/
156•arjunbajaj•18h ago•29 comments

Why are we still using Markdown?

https://bgslabs.org/blog/why-are-we-using-markdown/
124•veqq•15h ago•191 comments

Claude Code Found a Linux Vulnerability Hidden for 23 Years

https://mtlynch.io/claude-code-found-linux-vulnerability/
45•eichin•10h ago•18 comments

Scientists are working on "everything vaccines"

https://economist.com/science-and-technology/2026/04/01/scientists-are-working-on-everything-vacc...
23•andsoitis•4h ago•18 comments

Charge Robotics (YC S21) Is Hiring Software and Hardware Engineers

https://jobs.ashbyhq.com/charge-robotics
1•banks_h•12h ago

Fake Fans

https://www.wordsfromeliza.com/p/fake-fans
111•performative•11h ago•22 comments

The FAA’s flight restriction for drones is an attempt to criminalize filming ICE

https://www.eff.org/deeplinks/2026/04/faas-temporary-flight-restriction-drones-blatant-attempt-cr...
394•detaro•9h ago•114 comments