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.

QuadRF can spot drones and see WiFi through my wall

https://www.jeffgeerling.com/blog/2026/quadrf-can-spot-drones-and-see-wifi-through-my-wall/
295•speckx•4h ago•107 comments

Snails' teeth beats spider silk as nature's strongest material (2015)

https://www.smithsonianmag.com/smart-news/spider-silk-loses-top-spot-natures-strongest-material-s...
103•simonebrunozzi•3h ago•71 comments

GPT-5.6 Sol Ultra produces proof of the Cycle Double Cover Conjecture [pdf]

https://cdn.openai.com/pdf/04d1d1e4-bc75-476a-97cf-49055cd98d31/cdc_proof.pdf
148•scrlk•1h ago•130 comments

The tech of 'Terminator 2' – an oral history (2017)

https://vfxblog.com/2017/08/23/the-tech-of-terminator-2-an-oral-history/
98•markus_zhang•3h ago•41 comments

War Atlas: An interactive cartography of every named war in human history

https://waratlas.org
49•NaOH•2h ago•15 comments

New York City to become first in US to ban deceptive subscription practices

https://www.theguardian.com/us-news/2026/jul/10/new-york-city-deceptive-subscriptions-ban
140•randycupertino•2h ago•59 comments

Mayor Mamdani Announces Landmark "Click-to-Cancel" Consumer Protection Rules

https://www.nyc.gov/mayors-office/news/2026/07/mayor-mamdani-announces-landmark--click-to-cancel-...
53•thisislife2•56m ago•5 comments

Combustion Engine Web-Based Simulator

https://combustionlab.net
54•mytuny•5d ago•18 comments

Show HN: Wyrm – Solve algebra by touch, built on an open-source soundness engine

https://github.com/dicroce/wyrm_math
15•dicroce•1d ago•0 comments

Computation as a universal and fundamental concept

https://ergo.org/courses/computation-as-a-universal-and-fundamental-concept
42•simonpure•5h ago•43 comments

Ask HN: Are systems ready for the first negative leap second?

33•Asmod4n•4d ago•35 comments

Late Bronze Age Collapse

https://acoup.blog/2026/01/30/collections-the-late-bronze-age-collapse-a-very-brief-introduction/
265•dmonay•8h ago•176 comments

Good Tools Are Invisible

https://www.gingerbill.org/article/2026/07/10/good-tools-are-invisible/
264•theanonymousone•9h ago•130 comments

Lost city discovered beneath Egypt's desert with ancient church

https://www.dailymail.com/sciencetech/article-15956159/Incredible-lost-city-discovered-Egypts-des...
112•Bender•4d ago•53 comments

Materials innovation has a scale-up problem, not discovery

https://www.atomscale.ai/updates/our-thesis-atom-to-scale
9•groznyj•1h ago•0 comments

A Love Letter to Flashcards

https://lesleylai.info/en/flashcards/
103•surprisetalk•4h ago•60 comments

Successful Companies Go Blind

https://ianreppel.org/how-successful-companies-go-blind/
148•speckx•6h ago•54 comments

Write code like a human will maintain it

https://unstack.io/write-code-like-a-human-will-maintain-it
292•ScottWRobinson•6h ago•242 comments

45% of Enthusiasts 'Seriously Considering' Leaving Sony for PC

https://www.pushsquare.com/news/2026/07/ps5-has-put-a-dampener-on-gaming-45percent-of-enthusiasts...
28•speckx•1h ago•21 comments

Hands-On with the AMD Ryzen AI Halo

https://www.microcenter.com/site/mc-news/article/amd-ryzen-ai-halo-review.aspx
31•bdcravens•4h ago•27 comments

An Update on the scraper situation

https://lwn.net/SubscriberLink/1080822/990a8a5e2d379085/
5•chmaynard•47m ago•1 comments

Show HN: Reverse-engineering web apps into agent tools

67•pancomplex•1d ago•23 comments

Laylo (YC S20) Is Hiring a Head of Finance

https://www.ycombinator.com/companies/laylo/jobs/qce41D2-head-of-finance
1•amellin794•8h ago

The mathematical secrets of Barcelona's Sagrada Familia

https://mappingignorance.org/2026/06/30/sagrada-familia/
107•Gedxx•1w ago•27 comments

The Clouds of Hiroshima

https://doomsdaymachines.net/p/the-clouds-of-hiroshima
9•handfuloflight•3d ago•8 comments

Show HN: Reviving my 2001 college band with AI

https://www.fadingmaize.com
37•jacobgraf•1d ago•45 comments

Alternate Clock Designs and Time Systems

https://serialc.github.io/altClocks/
63•ethanpil•3d ago•37 comments

Cpp2Rust: Translates C++ to safe Rust automatically

https://github.com/Cpp2Rust/cpp2rust
25•signa11•4h ago•2 comments

In Emacs, Everything Looks Like a Service

http://yummymelon.com/devnull/in-emacs-everything-looks-like-a-service.html
150•kickingvegas•12h ago•89 comments

The Annotated JEPA

https://elonlit.com/scrivings/the-annotated-jepa/
46•surprisetalk•6h ago•9 comments