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.

Google Workspace CLI

https://github.com/googleworkspace/cli
225•gonzalovargas•3h ago•101 comments

Regulator contacts Meta over workers watching intimate AI glasses videos

https://www.bbc.com/news/articles/c0q33nvj0qpo
17•csomar•53m ago•1 comments

MacBook Neo

https://www.apple.com/newsroom/2026/03/say-hello-to-macbook-neo/
1634•dm•13h ago•1942 comments

Building a new Flash

https://bill.newgrounds.com/news/post/1607118
392•TechPlasma•7h ago•113 comments

Dario Amodei calls OpenAI’s messaging around military deal ‘straight up lies’

https://techcrunch.com/2026/03/04/anthropic-ceo-dario-amodei-calls-openais-messaging-around-milit...
321•SilverElfin•4h ago•153 comments

Something is afoot in the land of Qwen

https://simonwillison.net/2026/Mar/4/qwen/
567•simonw•12h ago•259 comments

Chaos and Dystopian news for the dead internet survivors

https://www.fubardaily.com
48•anonnona8878•2h ago•20 comments

Malm Whale

https://www.atlasobscura.com/places/malm-whale
10•thunderbong•4d ago•3 comments

What's driving rising business costs?

https://libertystreeteconomics.newyorkfed.org/2026/03/whats-driving-rising-business-costs/
27•jnord•3h ago•34 comments

NRC issues first commercial reactor construction approval in 10 years [pdf]

https://www.nrc.gov/sites/default/files/cdn/doc-collection-news/2026/26-028.pdf
62•Anon84•6h ago•31 comments

Moss is a pixel canvas where every brush is a tiny program

https://www.moss.town/
205•smusamashah•17h ago•25 comments

Humans 40k yrs ago developed a system of conventional signs

https://www.pnas.org/doi/10.1073/pnas.2520385123
79•bikenaga•11h ago•39 comments

What Python's asyncio primitives get wrong about shared state

https://www.inngest.com/blog/no-lost-updates-python-asyncio
7•goodoldneon•1h ago•6 comments

BMW Group to deploy humanoid robots in production in Germany for the first time

https://www.press.bmwgroup.com/global/article/detail/T0455864EN/bmw-group-to-deploy-humanoid-robo...
96•JeanKage•6h ago•76 comments

Jensen Huang says Nvidia is pulling back from OpenAI and Anthropic

https://techcrunch.com/2026/03/04/jensen-huang-says-nvidia-is-pulling-back-from-openai-and-anthro...
30•jnord•1h ago•1 comments

The View from RSS

https://www.carolinecrampton.com/the-view-from-rss/
89•Curiositry•7h ago•25 comments

NanoGPT Slowrun: Language Modeling with Limited Data, Infinite Compute

https://qlabs.sh/slowrun
136•sdpmas•10h ago•26 comments

“It turns out” (2010)

https://jsomers.net/blog/it-turns-out
254•Munksgaard•13h ago•80 comments

Picking Up a Zillion Pieces of Litter

https://www.sixstepstobetterhealth.com/litter.html
52•colinbartlett•3d ago•27 comments

Was Windows 1.0's lack of overlapping windows a legal or a technical matter?

https://retrocomputing.stackexchange.com/questions/32511/was-windows-1-0s-lack-of-overlapping-win...
63•SeenNotHeard•7h ago•41 comments

Qwen3.5 Fine-Tuning Guide

https://unsloth.ai/docs/models/qwen3.5/fine-tune
299•bilsbie•15h ago•70 comments

An interactive map of Flock Cams

https://deflock.org/map#map=5/37.125286/-96.284180
532•anjel•9h ago•196 comments

Show HN: A GFM+GF-MathJax/Latex HTML formatting adventure

https://github.com/scottvr/phart/blob/main/docs/GHM-LATEX.md
3•ycombiredd•3d ago•0 comments

A bit of fluid mechanics from scratch not from scratch

https://tsvibt.blogspot.com/2026/02/a-bit-of-fluid-mechanics-from-scratch.html
38•surprisetalk•2d ago•12 comments

Roboflow (YC S20) Is Hiring a Security Engineer for AI Infra

https://roboflow.com/careers
1•yeldarb•10h ago

Glaze by Raycast

https://www.glazeapp.com/
204•romac•14h ago•125 comments

Libre Solar – Open Hardware for Renewable Energy

https://libre.solar
223•evolve2k•3d ago•63 comments

US tech firms pledge at White House to bear costs of energy for datacenters

https://www.theguardian.com/us-news/2026/mar/04/us-tech-companies-energy-cost-pledge-white-house
37•geox•2h ago•27 comments

Raspberry Pi Pico as AM Radio Transmitter

https://www.pesfandiar.com/blog/2026/02/28/pico-am-radio-transmitter
76•pesfandiar•4d ago•31 comments

Daemon (2006)

https://en.wikipedia.org/wiki/Daemon_(novel)
27•solomonb•10h ago•6 comments