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

Comments

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

1M context is now generally available for Opus 4.6 and Sonnet 4.6

https://claude.com/blog/1m-context-ga
606•meetpateltech•14h ago•253 comments

A Survival Guide to a PhD (2016)

http://karpathy.github.io/2016/09/07/phd/
59•vismit2000•4d ago•17 comments

Emacs and Vim in the Age of AI

https://batsov.com/articles/2026/03/09/emacs-and-vim-in-the-age-of-ai/
106•psibi•4d ago•39 comments

Qatar helium shutdown puts chip supply chain on a two-week clock

https://www.tomshardware.com/tech-industry/qatar-helium-shutdown-puts-chip-supply-chain-on-a-two-...
537•johnbarron•19h ago•467 comments

Show HN: Channel Surfer – Watch YouTube like it’s cable TV

https://channelsurfer.tv
484•kilroy123•2d ago•144 comments

You gotta think outside the hypercube

https://lcamtuf.substack.com/p/you-gotta-think-outside-the-hypercube
29•surprisetalk•3d ago•2 comments

I found 39 Algolia admin keys exposed across open source documentation sites

https://benzimmermann.dev/blog/algolia-docsearch-admin-keys
119•kernelrocks•9h ago•28 comments

Mouser: An open source alternative to Logi-Plus mouse software

https://github.com/TomBadash/MouseControl
285•avionics-guy•13h ago•84 comments

Hammerspoon

https://github.com/Hammerspoon/hammerspoon
275•tosh•13h ago•97 comments

Atari 2600 BASIC Programming (2015)

https://huguesjohnson.com/programming/atari-2600-basic/
20•mondobe•2d ago•3 comments

Optimizing Content for Agents

https://cra.mr/optimizing-content-for-agents/
35•vinhnx•5h ago•15 comments

Can I run AI locally?

https://www.canirun.ai/
1180•ricardbejarano•19h ago•288 comments

Parallels confirms MacBook Neo can run Windows in a virtual machine

https://www.macrumors.com/2026/03/13/macbook-neo-runs-windows-11-vm/
253•tosh•18h ago•340 comments

Wired headphone sales are exploding

https://www.bbc.com/future/article/20260310-wired-headphones-are-better-than-bluetooth
85•billybuckwheat•2d ago•134 comments

Games with loot boxes to get minimum 16 age rating across Europe

https://www.bbc.com/news/articles/cge84xqjg5lo
158•gostsamo•8h ago•69 comments

Our Experience with I-Ready

https://moultano.wordpress.com/2026/03/12/our-experience-with-i-ready/
60•barry-cotter•7h ago•20 comments

Digg is gone again

https://digg.com/
152•hammerbrostime•13h ago•119 comments

New 'negative light' technology hides data transfers in plain sight

https://www.unsw.edu.au/newsroom/news/2026/03/New-negative-light-technology-hides-data-transfers-...
83•wjSgoWPm5bWAhXB•2d ago•48 comments

Elon Musk pushes out more xAI founders as AI coding effort falters

https://www.ft.com/content/e5fbc6c2-d5a6-4b97-a105-6a96ea849de5
411•merksittich•15h ago•623 comments

I beg you to follow Crocker's Rules, even if you will be rude to me

https://lr0.org/blog/p/crocker/
60•ghd_•9h ago•84 comments

Coding after coders: The end of computer programming as we know it?

https://www.nytimes.com/2026/03/12/magazine/ai-coding-programming-jobs-claude-chatgpt.html?smid=u...
113•angst•1d ago•114 comments

AEP (API Design Standard and Tooling Ecosystem)

https://aep.dev/
4•rambleraptor•3d ago•2 comments

Using Thunderbird for RSS

https://rubenerd.com/using-thunderbird-for-rss/
92•ingve•4d ago•24 comments

Launch HN: Spine Swarm (YC S23) – AI agents that collaborate on a visual canvas

https://www.getspine.ai/
93•a24venka•18h ago•66 comments

Show HN: Context Gateway – Compress agent context before it hits the LLM

https://github.com/Compresr-ai/Context-Gateway
74•ivzak•14h ago•46 comments

Stanford researchers report first recording of a blue whale's heart rate (2019)

https://news.stanford.edu/stories/2019/11/first-ever-recording-blue-whales-heart-rate
71•eatonphil•12h ago•40 comments

The Wyden Siren Goes Off Again: We’ll Be “Stunned” By What the NSA Is Doing

https://www.techdirt.com/2026/03/12/the-wyden-siren-goes-off-again-well-be-stunned-by-what-the-ns...
453•cf100clunk•16h ago•129 comments

John Carmack about open source and anti-AI activists

https://twitter.com/id_aa_carmack/status/2032460578669691171
305•tzury•14h ago•403 comments

Your phone is an entire computer

https://medhir.com/blog/your-phone-is-an-entire-computer
310•medhir•14h ago•267 comments

Launch HN: Captain (YC W26) – Automated RAG for Files

https://www.runcaptain.com/
50•CMLewis•16h ago•35 comments