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•11mo ago

Comments

LegionMammal978•11mo 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•11mo 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•11mo 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.

Qwen3.6-Max-Preview: Smarter, Sharper, Still Evolving

https://qwen.ai/blog?id=qwen3.6-max-preview
356•mfiguiere•5h ago•202 comments

Anduril, Palantir and SpaceX are changing how America wages war

https://www.economist.com/business/2026/04/20/anduril-palantir-and-spacex-are-changing-how-americ...
18•andsoitis•18m ago•2 comments

At long last, InfoWars is ours

https://theonion.com/at-long-last-infowars-is-ours/
371•HotGarbage•1h ago•136 comments

ggsql: A Grammar of Graphics for SQL

https://opensource.posit.co/blog/2026-04-20_ggsql_alpha_release/
259•thomasp85•6h ago•62 comments

GitHub's Fake Star Economy

https://awesomeagents.ai/news/github-fake-stars-investigation/
579•Liriel•10h ago•312 comments

The Theory of Interstellar Trade [pdf] (1978)

https://www.princeton.edu/~pkrugman/interstellar.pdf
57•AFF87•2h ago•18 comments

Kimi K2.6: Advancing Open-Source Coding

https://www.kimi.com/blog/kimi-k2-6
364•meetpateltech•3h ago•174 comments

We accepted surveillance as default

https://vivianvoss.net/blog/why-we-accepted-surveillance
149•speckx•2h ago•64 comments

10 years ago, someone wrote a test for Servo that included an expiry in 2026

https://mastodon.social/@jdm_/116429380667467307
129•luu•23h ago•80 comments

Bloom (YC P26) Is Hiring

https://www.ycombinator.com/companies/trybloom/jobs
1•RayFitzgerald•2h ago

Kefir C17/C23 Compiler

https://sr.ht/~jprotopopov/kefir/
35•conductor•2d ago•2 comments

M 7.4 earthquake – 100 km ENE of Miyako, Japan

https://earthquake.usgs.gov/earthquakes/eventpage/us6000sri7/
210•Someone•9h ago•89 comments

Atlassian enables default data collection to train AI

https://letsdatascience.com/news/atlassian-enables-default-data-collection-to-train-ai-f71343d8
348•kevcampb•6h ago•78 comments

WebUSB Extension for Firefox

https://github.com/ArcaneNibble/awawausb
129•tuananh•7h ago•102 comments

Sauna effect on heart rate

https://tryterra.co/research/sauna-effect-on-heart-rate
283•kyriakosel•5h ago•165 comments

Deezer says 44% of songs uploaded to its platform daily are AI-generated

https://techcrunch.com/2026/04/20/deezer-says-44-of-songs-uploaded-to-its-platform-daily-are-ai-g...
155•FiddlerClamp•3h ago•175 comments

Larry Tesler: A Personal History of Modeless Text Editing and Cut/Copy-Paste (2012)

https://dl.acm.org/doi/epdf/10.1145/2212877.2212896
25•aragonite•3d ago•6 comments

Chernobyl's last wedding

https://www.bbc.com/news/articles/c0q92lx8q75o
35•1659447091•1d ago•8 comments

Show HN: Alien – Self-hosting with remote management (written in Rust)

54•alongub•3h ago•17 comments

OpenClaw isn't fooling me. I remember MS-DOS

https://www.flyingpenguin.com/build-an-openclaw-free-secure-always-on-local-ai-agent/
218•feigewalnuss•11h ago•254 comments

The Palantir's Stasi Protocols

https://professorsigmund.com/praxis/palantir-stasi-protocols.html
73•Prof_Sigmund•1h ago•20 comments

Modern Rendering Culling Techniques

https://krupitskas.com/posts/modern_culling_techniques/
10•krupitskas•1d ago•2 comments

All phones sold in the EU to have replaceable batteries from 2027

https://www.theolivepress.es/spain-news/2026/04/20/eu-to-force-replaceable-batteries-in-phones-an...
671•ramonga•5h ago•569 comments

I prompted ChatGPT, Claude, Perplexity, and Gemini and watched my Nginx logs

https://surfacedby.com/blog/nginx-logs-ai-traffic-vs-referral-traffic
111•startages•3h ago•19 comments

I'm never buying another Kindle

https://www.androidauthority.com/amazon-kindle-2026-3657863/
155•mikhael•3h ago•128 comments

Focused microwaves allow 3D printers to fuse circuits onto almost anything

https://newatlas.com/electronics/meta-nfc-focused-microwaves-circuits/
127•breve•2d ago•23 comments

NSA is using Anthropic's Mythos despite blacklist

https://www.axios.com/2026/04/19/nsa-anthropic-mythos-pentagon
384•Palmik•9h ago•270 comments

Ask HN: How to solve the cold start problem for a two-sided marketplace?

103•alegd•5h ago•104 comments

Up to 8M Bees Are Living in an Underground Network Beneath This Cemetery

https://www.discovermagazine.com/up-to-8-million-bees-are-living-in-an-underground-network-beneat...
153•janandonly•2d ago•27 comments

Quantum Computers Are Not a Threat to 128-Bit Symmetric Keys

https://words.filippo.io/128-bits/
12•hasheddan•2h ago•3 comments