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•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.

Flipper One – we need your help

https://blog.flipper.net/flipper-one-we-need-your-help/
710•sandebert•5h ago•322 comments

Indexing a year of video locally on a 2021 MacBook with Gemma4-31B (50GB swap)

https://blog.simbastack.com/indexed-a-year-of-video-locally/
91•asenna•2h ago•26 comments

Python 3.15: features that didn't make the headlines

https://blog.changs.co.uk/python-315-features-that-didnt-make-the-headlines.html
208•rbanffy•5h ago•91 comments

We're testing new ad formats in Search and expanding our Direct Offers pilot

https://blog.google/products/ads-commerce/google-marketing-live-search-ads/
455•sofumel•7h ago•383 comments

Michael Keating has died

https://www.bigfinish.com/news/v/michael-keating-1947-2026
47•speckx•2h ago•27 comments

Lost Images from the 1945 Trinity Nuclear Test Restored

https://spectrum.ieee.org/trinity-nuclear-test
149•pseudolus•5h ago•51 comments

Launch HN: Runtime (YC P26) – Sandboxed coding agents for everyone on a team

https://www.runtm.com/
11•gustrigos•49m ago•0 comments

Mounting Git commits as folders with NFS

https://jvns.ca/blog/2023/12/04/mounting-git-commits-as-folders-with-nfs/
32•pvtmert•2d ago•14 comments

FatGid: FreeBSD 14.x kernel local privilege escalation

https://fatgid.io/
57•WhyNotHugo•4h ago•14 comments

London Mayor Blocks Palantir

https://www.theguardian.com/uk-news/2026/may/21/london-mayor-sadiq-khan-blocks-met-police-deal-wi...
29•ZiiS•21m ago•6 comments

What Is Happening to Publishing?

https://resobscura.substack.com/p/what-is-happening-to-publishing
10•benbreen•1d ago•0 comments

Vivaldi 8.0

https://vivaldi.com/blog/vivaldi-on-desktop-8-0/
226•OuterVale•9h ago•161 comments

Who Wins and Who Loses in Prediction Markets? Evidence from Polymarket

https://papers.ssrn.com/sol3/papers.cfm?abstract_id=6443103
86•vcf•4h ago•60 comments

Google's Antigravity Bait and Switch

https://www.0xsid.com/blog/antigravity-bait-n-switch
276•ssiddharth•3h ago•148 comments

We Reverse-Engineered Docker Sandbox's Undocumented MicroVM API

https://rivet.dev/blog/2026-02-04-we-reverse-engineered-docker-sandbox-undocumented-microvm-api/
21•yakkomajuri•2h ago•1 comments

Cekura (YC F24) Is Hiring

https://www.ycombinator.com/companies/cekura-ai/jobs/AiWwUxI-forward-deployed-engineer-us
1•atarus•4h ago

Show HN: Rmux – A programmable terminal multiplexer with a Playwright-style SDK

https://github.com/helvesec/rmux
140•shideneyu•7h ago•67 comments

Waymo pauses Atlanta service as its robotaxis keep driving into floods

https://techcrunch.com/2026/05/21/waymo-pauses-atlanta-service-as-its-robotaxis-keep-driving-into...
6•mattas•25m ago•3 comments

Show HN: I Dedicated 4 Years to Mastering Offline Password Cracking

87•bojta-lepenye•4h ago•5 comments

AI is just unauthorised plagiarism at a bigger scale

https://axelk.ee/ai-is-just-unauthorised-plagiarism-at-a-bigger-scale/
567•speckx•3h ago•437 comments

A Bipartisan Amendment Would End Police License Plate Tracking Nationwide

https://www.wired.com/story/a-bipartisan-amendment-would-end-police-license-plate-tracking-nation...
120•cdrnsf•3h ago•33 comments

What Do Gödel's Incompleteness Theorems Mean?

https://www.quantamagazine.org/what-do-godels-incompleteness-theorems-truly-mean-20260518/
85•baruchel•2d ago•39 comments

IBM invented semiconductor manufacturing automation

https://spectrum.ieee.org/semiconductor-fabrication
48•rbanffy•6h ago•1 comments

Get your passwords out of Bitwarden while you still can

https://www.osnews.com/story/145029/get-your-passwords-out-of-bitwarden-while-you-still-can/
134•speckx•2h ago•97 comments

No Slop Grenade

https://noslopgrenade.com/
284•napolux•7h ago•173 comments

Show HN: I reverse engineered Apple's video wallpapers

https://github.com/kageroumado/phosphene
374•kageroumado•17h ago•92 comments

Flipper One Tech Specs

https://docs.flipper.net/one/general/tech-specs
484•gregsadetsky•22h ago•160 comments

The Letter S, by Donald Knuth (1980) [pdf]

https://gwern.net/doc/design/typography/1980-knuth.pdf
245•bambax•16h ago•43 comments

An OpenAI model has disproved a central conjecture in discrete geometry

https://openai.com/index/model-disproves-discrete-geometry-conjecture/
1331•tedsanders•21h ago•961 comments

Haskell Foundation 2026 Update

https://discourse.haskell.org/t/haskell-foundation-2026-update/14136
163•azhenley•14h ago•58 comments