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
485•takira•7h ago•212 comments

Furiosa: 3.5x efficiency over H100s

https://furiosa.ai/blog/introducing-rngd-server-efficient-ai-inference-at-data-center-scale
77•written-beyond•2h ago•39 comments

Scaling long-running autonomous coding

https://cursor.com/blog/scaling-agents
130•samwillis•4h ago•64 comments

Bubblewrap: A nimble way to prevent agents from accessing your .env files

https://patrickmccanna.net/a-better-way-to-limit-claude-code-and-other-coding-agents-access-to-se...
13•0o_MrPatrick_o0•1h ago•9 comments

Ask HN: Share your personal website

422•susam•10h ago•1340 comments

The State of OpenSSL for pyca/cryptography

https://cryptography.io/en/latest/statements/state-of-openssl/
82•SGran•5h ago•16 comments

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

https://webtiles.kicya.net/
128•dimden•5d ago•19 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...
455•OptionOfT•4d ago•244 comments

Generate QR Codes with Pure SQL in PostgreSQL

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

SparkFun Officially Dropping AdaFruit due to CoC Violation

https://www.sparkfun.com/official-response
402•yaleman•12h ago•400 comments

Sun Position Calculator

https://drajmarsh.bitbucket.io/earthsun.html
66•sanbor•5h ago•14 comments

ChromaDB Explorer

https://www.chroma-explorer.com/
33•arsentjev•4h ago•1 comments

Find a pub that needs you

https://www.ismypubfucked.com/
225•thinkingemote•11h ago•188 comments

How can I build a simple pulse generator to demonstrate transmission lines

https://electronics.stackexchange.com/questions/764155/how-can-i-build-a-simple-pulse-generator-t...
18•alphabetter•5d ago•4 comments

Roam 50GB is now Roam 100GB

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

I hate GitHub Actions with passion

https://xlii.space/eng/i-hate-github-actions-with-passion/
433•xlii•16h ago•298 comments

Native ZFS VDEV for Object Storage (OpenZFS Summit)

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

Rubik's Cube in Prolog – Order

https://medium.com/@kenichisasagawa/i-am-preparing-material-for-a-prolog-book-af7580acfee7
22•myth_drannon•4d ago•6 comments

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

https://github.com/cosinusalpha/webctl
69•cosinusalpha•12h ago•21 comments

You Need a Kitchen Slide Rule

https://entropicthoughts.com/kitchen-slide-rule
3•aebtebeten•1d ago•2 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-...
476•MBCook•9h ago•659 comments

Crafting Interpreters

https://craftinginterpreters.com/
21•tosh•4h ago•5 comments

The hunt for a stolen Jackson Pollock

https://www.washingtonpost.com/entertainment/art/interactive/2026/jackson-pollock-theft-isaacs-fa...
21•prismatic•18h ago•3 comments

Media Player Classic Qute Theater

https://github.com/mpc-qt/mpc-qt
9•XzetaU8•3d ago•2 comments

Is Rust faster than C?

https://steveklabnik.com/writing/is-rust-faster-than-c/
232•vincentchau•4d ago•265 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
234•evakhoury•10h ago•220 comments

Anthropic Explicitly Blocking OpenCode

https://gist.github.com/R44VC0RP/bd391f6a23185c0fed6c6b5fb2bac50e
125•ryanvogel•3h ago•100 comments

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

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

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

63•nico•8h ago•88 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
166•paulpauper•7h ago•213 comments