frontpage.
newsnewestaskshowjobs

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•1y ago

Comments

LegionMammal978•1y 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•1y 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•1y 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.

Kaiser nurses say AI, workplace surveillance are making their jobs, care worse

https://localnewsmatters.org/2026/07/15/kaiser-nurses-say-ai-workplace-surveillance-are-making-th...
419•gnabgib•7h ago•269 comments

AWS: Inaccurate Estimated Billing Data – $1.7 billion

1115•nprateem•19h ago•663 comments

Thanks HN for 15 years of support and helping me find my life's work

471•nicholasjbs•12h ago•48 comments

Reviving a 15-year-old netbook with Arch Linux

https://parksb.github.io/en/article/41.html
30•parksb•3d ago•11 comments

The Zilog Z80 has turned 50

https://goliath32.com/blog/z80.html
193•st_goliath•9h ago•61 comments

First atmosphere found on Earth-like planet in habitable zone of distant star

https://www.bbc.com/news/articles/cy4kdd1e0ejo
409•neversaydie•15h ago•250 comments

Moonstone: Modern, cross-platform Lua runtime and package manager written in Zig

https://moonstone.sh/
29•ksymph•4h ago•9 comments

Shipping OpenStrike: A Counter-Strike-Shaped FPS on a 2004 Handheld

https://pocketjs.dev/blog/shipping-openstrike/
20•itvision•6d ago•8 comments

TP-Link Kasa cameras leaked home GPS via unauthenticated UDP for 6 years

https://github.com/BadChemical/IoT-Vulnerability-Research-Public/blob/main/TP-Link_Kasa_EC71/Kasa...
71•BadChemical•7h ago•17 comments

I Started a "Dirt Notebook"

https://pinewind.bearblog.dev/i-started-a-dirt-notebook/
36•herbertl•4h ago•28 comments

Learning a few things about running SQLite

https://jvns.ca/blog/2026/07/17/learning-about-running-sqlite/
204•surprisetalk•11h ago•51 comments

The Isomorphic Labs Drug Design Engine unlocks a new frontier beyond AlphaFold

https://www.isomorphiclabs.com/articles/the-isomorphic-labs-drug-design-engine-unlocks-a-new-fron...
56•andsoitis•6h ago•6 comments

Stenchill: 3D Printable Solder Paste Stencil Generator

https://www.stenchill.com/en/
27•radeeyate•4h ago•4 comments

Kimi K3, and what we can still learn from the pelican benchmark

https://simonwillison.net/2026/Jul/16/kimi-k3/
304•droidjj•15h ago•161 comments

DrDroid (YC W23) Is Hiring

https://www.ycombinator.com/companies/drdroid/jobs/w45QcNV-product-engineer-assignment-mandatory
1•TheBengaluruGuy•4h ago

Vāgdhenu: A Sanskrit Chanting TTS System

https://prathosh.in/vagdhenu/
118•subinalex•4d ago•20 comments

An Update on Igalia's Layer Based SVG Engine in WebKit (Reducing Layer Overhead)

https://blogs.igalia.com/nzimmermann/posts/2026-07-14-lbse-conditional-layers/
28•bkardell•3d ago•1 comments

Static search trees: 40x faster than binary search (2024)

https://curiouscoding.nl/posts/static-search-tree/
77•lalitmaganti•9h ago•3 comments

Open Book Touch: open-source e-reader

https://www.crowdsupply.com/oddly-specific-objects/open-book-touch
83•surprisetalk•8h ago•23 comments

Lego building instructions through time

https://www.lego.com/en-us/history/articles/d-lego-building-instructions-through-time
92•NaOH•11h ago•18 comments

Painting the sides of railroad rails white to reduce derailment

https://www.up.com/news/safety/Tracking-Rail-Heat-260608
71•zdw•9h ago•40 comments

Battery packs: Let's talk about crates, baby

https://smallcultfollowing.com/babysteps/blog/2026/07/15/battery-packs/
4•MeetingsBrowser•1d ago•0 comments

Mac gaming is finally getting the overpowered upgrade it deserves

https://www.macworld.com/article/3189951/apples-latest-game-porting-toolkit-beta-changed-how-i-th...
19•kristianp•1h ago•10 comments

The state of open source AI

https://stateofopensource.ai/
404•rellem•15h ago•294 comments

Frank Lloyd Wright’s first home

https://www.architecturaldigest.com/story/frank-lloyd-wright-home-and-studio-everything-you-need-...
95•NaOH•5d ago•47 comments

Show HN: A zoomable timeline of 4M Wikipedia events

https://app.everything.diena.co/
73•lortex•10h ago•30 comments

FAA lets Boeing sign off on 737 MAX, 787 airworthiness certificates again

https://www.cnbc.com/2026/07/17/faa-boeing-737-max-787.html
158•hmm37•8h ago•86 comments

Three ways people respond to a problem (other than solving it)

https://improvesomething.today/responses-to-problems/
217•surprisetalk•15h ago•120 comments

Regressive JPEGs

https://maurycyz.com/projects/bad_jpeg/
6•vitaut•2h ago•0 comments

Show HN: Watch bots interact with an SSH honeypot in real time

https://honeypotlive.cc/
150•tusksm•15h ago•54 comments