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.

Cowork: Claude Code for the rest of your work

https://claude.com/blog/cowork-research-preview
838•adocomplete•11h ago•386 comments

TimeCapsuleLLM: LLM trained only on data from 1800-1875

https://github.com/haykgrigo3/TimeCapsuleLLM
555•admp•14h ago•227 comments

The Cray-1 Computer System (1977) [pdf]

https://s3data.computerhistory.org/brochures/cray.cray1.1977.102638650.pdf
75•LordGrey•3d ago•42 comments

Postal Arbitrage

https://walzr.com/postal-arbitrage
352•The28thDuck•13h ago•181 comments

Implementing a web server in a single printf() call (2014)

https://tinyhack.com/2014/03/12/implementing-a-web-server-in-a-single-printf-call/
26•nateb2022•4d ago•2 comments

The chess bot on Delta Air Lines will destroy you (2024) [video]

https://www.youtube.com/watch?v=c0mLhHDcY3I
206•cjaackie•10h ago•158 comments

Provenance Is the New Version Control

https://aicoding.leaflet.pub/3mcbiyal7jc2y
22•gpi•3h ago•15 comments

Floppy disks turn out to be the greatest TV remote for kids

https://blog.smartere.dk/2026/01/floppy-disks-the-best-tv-remote-for-kids/
557•mchro•17h ago•324 comments

Some ecologists fear their field is losing touch with nature

https://www.nature.com/articles/d41586-025-04150-w
89•Growtika•4d ago•39 comments

Unauthenticated remote code execution in OpenCode

https://cy.md/opencode-rce/
288•CyberShadow•1d ago•88 comments

HP Reveals Keyboard Computer with Ryzen AI Chip

https://www.hp.com/us-en/desktops/business/eliteboard.html
26•tonymet•5d ago•31 comments

Date is out, Temporal is in

https://piccalil.li/blog/date-is-out-and-temporal-is-in/
354•alexanderameye•15h ago•135 comments

Fabrice Bellard's TS Zip (2024)

https://www.bellard.org/ts_zip/
133•everlier•10h ago•56 comments

LLVM: The bad parts

https://www.npopov.com/2026/01/11/LLVM-The-bad-parts.html
317•vitaut•16h ago•60 comments

Text-Based Web Browsers

https://cssence.com/2026/text-based-web-browsers/
11•pabs3•1h ago•4 comments

Apple picks Gemini to power Siri

https://www.cnbc.com/2026/01/12/apple-google-ai-siri-gemini.html
777•stygiansonic•15h ago•455 comments

Kafka Inc

https://libertiesjournal.com/online-articles/kafkainc/
5•Caiero•5d ago•1 comments

Show HN: AI in SolidWorks

https://www.trylad.com
147•WillNickols•13h ago•79 comments

Anthropic made a mistake in cutting off third-party clients

https://archaeologist.dev/artifacts/anthropic
265•codesparkle•19h ago•186 comments

Show HN: Yolobox – Run AI coding agents with full sudo without nuking home dir

https://github.com/finbarr/yolobox
75•Finbarr•12h ago•59 comments

F2 (YC S25) Is Hiring

https://www.ycombinator.com/companies/f2/jobs/cJsc7Fe-product-designer
1•arctech•8h ago

Show HN: Agent-of-empires: OpenCode and Claude Code session manager

https://github.com/njbrake/agent-of-empires
85•river_otter•16h ago•23 comments

Windows 8 Desktop Environment for Linux

https://github.com/er-bharat/Win8DE
173•edent•17h ago•157 comments

The struggle of resizing windows on macOS Tahoe

https://noheger.at/blog/2026/01/11/the-struggle-of-resizing-windows-on-macos-tahoe/
2605•happosai•1d ago•1110 comments

Ozempic is changing the foods Americans buy

https://news.cornell.edu/stories/2025/12/ozempic-changing-foods-americans-buy
376•giuliomagnifico•18h ago•667 comments

Why BM25 queries with more terms can be faster (and other scaling surprises)

https://turbopuffer.com/blog/bm25-latency-musings
15•_peregrine_•4d ago•0 comments

Google removes AI health summaries after investigation finds dangerous flaws

https://arstechnica.com/ai/2026/01/google-removes-some-ai-health-summaries-after-investigation-fi...
144•barishnamazov•7h ago•83 comments

Show HN: Fall asleep by watching JavaScript load

https://github.com/sarusso/bedtime
60•sarusso•12h ago•21 comments

Zen-C: Write like a high-level language, run like C

https://github.com/z-libs/Zen-C
180•simonpure•17h ago•107 comments

Message Queues: A Simple Guide with Analogies (2024)

https://www.cloudamqp.com/blog/message-queues-exaplined-with-analogies.html
91•byt3h3ad•13h ago•25 comments