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.

The URL shortener that makes your links look as suspicious as possible

https://creepylink.com/
119•dreadsword•2h ago•28 comments

Claude Cowork exfiltrates files

https://www.promptarmor.com/resources/claude-cowork-exfiltrates-files
569•takira•9h ago•234 comments

Furiosa: 3.5x efficiency over H100s

https://furiosa.ai/blog/introducing-rngd-server-efficient-ai-inference-at-data-center-scale
122•written-beyond•4h ago•61 comments

Show HN: Sparrow-1 – Audio-native model for human-level turn-taking without ASR

https://www.tavus.io/post/sparrow-1-human-level-conversational-timing-in-real-time-voice
21•code_brian•11h ago•2 comments

Ask HN: What is the best way to provide continuous context to models?

30•nemath•4h ago•13 comments

Scaling long-running autonomous coding

https://cursor.com/blog/scaling-agents
162•samwillis•7h ago•78 comments

Ask HN: Share your personal website

495•susam•12h ago•1473 comments

Ask HN: What did you find out or explore today?

31•blahaj•11h ago•21 comments

New Safari developer tools provide insight into CSS Grid Lanes

https://webkit.org/blog/17746/new-safari-developer-tools-provide-insight-into-css-grid-lanes/
14•feross•5h ago•1 comments

Project SkyWatch (a.k.a. Wescam at Home)

https://ianservin.com/2026/01/13/project-skywatch-aka-wescam-at-home/
8•jjwiseman•12h ago•2 comments

The State of OpenSSL for pyca/cryptography

https://cryptography.io/en/latest/statements/state-of-openssl/
110•SGran•7h ago•18 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...
51•0o_MrPatrick_o0•4h ago•45 comments

First impressions of Claude Cowork

https://simonw.substack.com/p/first-impressions-of-claude-cowork
15•stosssik•23h ago•1 comments

Eigent: An open source Claude Cowork alternative

https://github.com/eigent-ai/eigent
11•WorldPeas•12h ago•2 comments

Ask HN: How are you doing RAG locally?

53•tmaly•15h ago•17 comments

Ask HN: Weird archive.today behavior?

50•rabinovich•7h ago•17 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...
479•OptionOfT•4d ago•251 comments

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

https://webtiles.kicya.net/
151•dimden•5d ago•22 comments

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

https://github.com/cosinusalpha/webctl
78•cosinusalpha•15h ago•24 comments

SparkFun Officially Dropping AdaFruit due to CoC Violation

https://www.sparkfun.com/official-response
425•yaleman•15h ago•428 comments

Sun Position Calculator

https://drajmarsh.bitbucket.io/earthsun.html
86•sanbor•8h ago•19 comments

ChromaDB Explorer

https://www.chroma-explorer.com/
47•arsentjev•7h ago•3 comments

Find a pub that needs you

https://www.ismypubfucked.com/
244•thinkingemote•14h ago•193 comments

Generate QR Codes with Pure SQL in PostgreSQL

https://tanelpoder.com/posts/generate-qr-code-with-pure-sql-in-postgres/
67•tanelpoder•4d ago•5 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...
30•alphabetter•5d ago•6 comments

Crafting Interpreters

https://craftinginterpreters.com/
54•tosh•7h ago•8 comments

Roam 50GB is now Roam 100GB

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

I Designed a Custom Protocol for My App

https://blog.roj.dev/how-i-designed-a-custom-protocol-for-my-app
4•_roj•2d ago•2 comments

Is Rust faster than C?

https://steveklabnik.com/writing/is-rust-faster-than-c/
249•vincentchau•4d ago•274 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-...
530•MBCook•12h ago•707 comments