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
982•adocomplete•15h ago•438 comments

FOSS in times of war, scarcity and (adversarial) AI [video]

https://fosdem.org/2026/schedule/event/FE7ULY-foss-in-times-of-war-scarcity-and-ai/
11•maelito•1h ago•2 comments

Text-Based Web Browsers

https://cssence.com/2026/text-based-web-browsers/
96•pabs3•5h ago•41 comments

TimeCapsuleLLM: LLM trained only on data from 1800-1875

https://github.com/haykgrigo3/TimeCapsuleLLM
619•admp•18h ago•253 comments

U.S. Emissions Jumped in 2025 as Coal Power Rebounded

https://www.nytimes.com/2026/01/13/climate/us-emissions-2025-coal-power.html
20•fleahunter•50m ago•2 comments

Postal Arbitrage

https://walzr.com/postal-arbitrage
409•The28thDuck•17h ago•205 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/
634•mchro•21h ago•356 comments

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

https://s3data.computerhistory.org/brochures/cray.cray1.1977.102638650.pdf
99•LordGrey•3d ago•52 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/
55•nateb2022•4d ago•4 comments

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

https://www.youtube.com/watch?v=c0mLhHDcY3I
240•cjaackie•14h ago•217 comments

Unauthenticated remote code execution in OpenCode

https://cy.md/opencode-rce/
335•CyberShadow•1d ago•110 comments

Some ecologists fear their field is losing touch with nature

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

Date is out, Temporal is in

https://piccalil.li/blog/date-is-out-and-temporal-is-in/
387•alexanderameye•19h ago•156 comments

Fabrice Bellard's TS Zip (2024)

https://www.bellard.org/ts_zip/
166•everlier•14h ago•68 comments

Chromium Has Merged JpegXL

https://chromium-review.googlesource.com/c/chromium/src/+/7184969
111•thunderbong•4h ago•19 comments

UK Expands Online Safety Act to Mandate Preemptive Scanning

https://reclaimthenet.org/uk-expands-online-safety-act-to-mandate-preemptive-scanning
11•aftergibson•50m ago•3 comments

Apple picks Gemini to power Siri

https://www.cnbc.com/2026/01/12/apple-google-ai-siri-gemini.html
853•stygiansonic•19h ago•528 comments

LLVM: The bad parts

https://www.npopov.com/2026/01/11/LLVM-The-bad-parts.html
339•vitaut•20h ago•66 comments

Designing an IPv6-native P2P transport – lessons from building I6P

https://theushen.medium.com/designing-an-ipv6-native-p2p-transport-lessons-from-building-i6p-b8ca...
8•TheusHen•3d ago•1 comments

Justice Delayed Is Justice Denied

https://en.wikipedia.org/wiki/Justice_delayed_is_justice_denied
15•barrister•1h ago•0 comments

Zirgen: Compiler for a Domain-Specific Language

https://github.com/risc0/zirgen
11•0xkato•4d ago•0 comments

Show HN: AI in SolidWorks

https://www.trylad.com
163•WillNickols•17h ago•87 comments

Anthropic made a mistake in cutting off third-party clients

https://archaeologist.dev/artifacts/anthropic
303•codesparkle•23h ago•200 comments

Data Exfiltration via DNS Resolution

https://github.com/anthropic-experimental/sandbox-runtime/issues/88
6•m-hodges•3h ago•0 comments

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

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

Windows 8 Desktop Environment for Linux

https://github.com/er-bharat/Win8DE
195•edent•21h ago•191 comments

F2 (YC S25) Is Hiring

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

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

https://github.com/finbarr/yolobox
88•Finbarr•16h ago•67 comments

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

https://github.com/njbrake/agent-of-empires
95•river_otter•20h ago•34 comments

The struggle of resizing windows on macOS Tahoe

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