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

Comments

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

Claude Cowork Exfiltrates Files

https://www.promptarmor.com/resources/claude-cowork-exfiltrates-files
291•takira•3h ago•142 comments

Scaling long-running autonomous coding

https://cursor.com/blog/scaling-agents
46•samwillis•1h ago•20 comments

The State of OpenSSL for pyca/cryptography

https://cryptography.io/en/latest/statements/state-of-openssl/
31•SGran•1h ago•3 comments

Show HN: WebTiles – create a tiny 250x250 website with neighbors around you

https://webtiles.kicya.net/
91•dimden•4d ago•12 comments

Sun Position Calculator

https://drajmarsh.bitbucket.io/earthsun.html
38•sanbor•1h ago•6 comments

Ask HN: Share your personal website

332•susam•6h ago•1119 comments

Why some clothes shrink in the wash and how to unshrink them

https://www.swinburne.edu.au/news/2025/08/why-some-clothes-shrink-in-the-wash-and-how-to-unshrink...
397•OptionOfT•3d ago•216 comments

Show HN: Webctl – Browser automation for agents based on CLI instead of MCP

https://github.com/cosinusalpha/webctl
51•cosinusalpha•8h ago•6 comments

Roam 50GB is now Roam 100GB

https://starlink.com/support/article/58c9c8b7-474e-246f-7e3c-06db3221d34d
226•bahmboo•7h ago•244 comments

SparkFun Officially Dropping AdaFruit due to CoC Violation

https://www.sparkfun.com/official-response
336•yaleman•8h ago•338 comments

Find a pub that needs you

https://www.ismypubfucked.com/
172•thinkingemote•7h ago•134 comments

Native ZFS VDEV for Object Storage (OpenZFS Summit)

https://www.zettalane.com/blog/openzfs-summit-2025-mayanas-objbacker.html
55•suprasam•4h ago•8 comments

I hate GitHub Actions with passion

https://xlii.space/eng/i-hate-github-actions-with-passion/
379•xlii•12h ago•285 comments

Ford F-150 Lightning outsold the Cybertruck and was then canceled for poor sales

https://electrek.co/2026/01/13/ford-f150-lightning-outsold-tesla-cybertruck-canceled-not-selling-...
356•MBCook•6h ago•470 comments

Training my smartwatch to track intelligence

https://dmvaldman.github.io/rooklift/
5•dmvaldman•1h ago•2 comments

Ask HN: How do you safely give LLMs SSH/DB access?

41•nico•4h ago•66 comments

Generate QR Codes with Pure SQL in PostgreSQL

https://tanelpoder.com/posts/generate-qr-code-with-pure-sql-in-postgres/
7•tanelpoder•4d ago•0 comments

The Influentists: AI hype without proof

https://carette.xyz/posts/influentists/
167•LucidLynx•2h ago•96 comments

So, you’ve hit an age gate. What now?

https://www.eff.org/deeplinks/2026/01/so-youve-hit-age-gate-what-now
272•hn_acker•5h ago•226 comments

Ski map artist James Niehues, the 'Monet of the mountains' (2021)

https://adventure.com/ski-map-artist-james-niehues/
93•gyomu•4d ago•9 comments

You Can Just Buy Far-UVC

https://www.jefftk.com/p/you-can-just-buy-far-uvc
52•surprisetalk•4d ago•69 comments

Show HN: Digital Carrot – Block social media with programmable rules and goals

https://www.digitalcarrot.app/
28•newswangerd•8h ago•11 comments

The hunt for a stolen Jackson Pollock

https://www.washingtonpost.com/entertainment/art/interactive/2026/jackson-pollock-theft-isaacs-fa...
5•prismatic•15h ago•0 comments

Every country should set 16 as the minimum age for social media accounts

https://www.afterbabel.com/p/why-every-country-should-set-16
86•paulpauper•3h ago•130 comments

ChromaDB Explorer

https://www.chroma-explorer.com/
5•arsentjev•51m ago•0 comments

GitHub should charge everyone $1 more per month to fund open source

https://blog.greg.technology/2025/11/27/github-should-charge-1-dollar-more-per-month.html
186•evakhoury•6h ago•174 comments

Simple to Ornate and Back Again (2024)

https://josem.co/simple-to-ornate-and-back-again/
3•nikodunk•1h ago•0 comments

Lago (Open-Source Billing) is hiring across teams and geos

1•Rafsark•10h ago

Is Rust faster than C?

https://steveklabnik.com/writing/is-rust-faster-than-c/
193•vincentchau•4d ago•233 comments

I’m leaving Redis for SolidQueue

https://www.simplethread.com/redis-solidqueue/
290•amalinovic•13h ago•122 comments