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

Comments

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

What will enter the public domain in 2026?

https://publicdomainreview.org/features/entering-the-public-domain/2026/
136•herbertl•3h ago•32 comments

Beej's Guide to Learning Computer Science

https://beej.us/guide/bglcs/html/split/
127•intelkishan•2h ago•22 comments

DeepSeek-v3.2: Pushing the frontier of open large language models [pdf]

https://huggingface.co/deepseek-ai/DeepSeek-V3.2/resolve/main/assets/paper.pdf
691•pretext•14h ago•331 comments

India orders smartphone makers to preload state-owned cyber safety app

https://www.reuters.com/sustainability/boards-policy-regulation/india-orders-mobile-phones-preloa...
581•jmsflknr•1d ago•338 comments

Tom Stoppard has died

https://www.bbc.com/news/articles/c74xe49q7vlo
51•mstep•2d ago•6 comments

Reverse math shows why hard problems are hard

https://www.quantamagazine.org/reverse-mathematics-illuminates-why-hard-problems-are-hard-20251201/
52•gsf_emergency_6•3h ago•5 comments

Beej's Guide to C Programming

https://beej.us/guide/bgc/
4•tambourine_man•12m ago•2 comments

Decreasing Certificate Lifetimes to 45 Days

https://letsencrypt.org/2025/12/02/from-90-to-45.html
30•abraham•3h ago•2 comments

Frequently Asked Unicycling Questions

https://vale.rocks/posts/unicycle-faq
9•edent•1h ago•3 comments

Ghostty compiled to WASM with xterm.js API compatibility

https://github.com/coder/ghostty-web
293•kylecarbs•12h ago•92 comments

Ask HN: Who is hiring? (December 2025)

245•whoishiring•14h ago•323 comments

Notes on Bhutan

https://apropos.substack.com/p/notes-on-bhutan
7•sg5421•5h ago•0 comments

Arcee Trinity Mini: US-Trained Moe Model

https://www.arcee.ai/blog/the-trinity-manifesto?src=hn
47•hurrycane•6h ago•10 comments

Codex, Opus, Gemini try to build Counter Strike

https://www.instantdb.com/essays/agents_building_counterstrike
156•stopachka•3d ago•37 comments

Cartographers have been hiding illustrations inside Switzerland’s maps (2020)

https://eyeondesign.aiga.org/for-decades-cartographers-have-been-hiding-covert-illustrations-insi...
286•mhb•16h ago•54 comments

Tested: 1981 Datsun 280ZX Turbo (1981)

https://www.caranddriver.com/reviews/a69529696/1981-datsun-280-zx-turbo-archive-test/
35•RickJWagner•2d ago•43 comments

AI agents find $4.6M in blockchain smart contract exploits

https://red.anthropic.com/2025/smart-contracts/
150•bpierre•6h ago•77 comments

Google, Nvidia, and OpenAI

https://stratechery.com/2025/google-nvidia-and-openai/
159•tambourine_man•15h ago•145 comments

A Bus Ride and the (At Least) 3x UX FAILs

https://bsdly.blogspot.com/2025/11/a-bus-ride-and-at-least-3x-ux-fails.html
3•zdw•2d ago•0 comments

Google unkills JPEG XL?

https://tonisagrista.com/blog/2025/google-unkills-jpegxl/
284•speckx•15h ago•215 comments

Last Week on My Mac: Losing confidence

https://eclecticlight.co/2025/11/30/last-week-on-my-mac-losing-confidence/
349•frizlab•7h ago•186 comments

10 years of writing a blog nobody reads

https://flowtwo.io/post/on-10-years-of-writing-a-blog-nobody-reads
176•thejoeflow•4d ago•91 comments

Dark Corners of Unicode (2015)

https://eev.ee/blog/2015/09/12/dark-corners-of-unicode/
9•cratermoon•3d ago•1 comments

John Giannandrea to retire from Apple

https://www.apple.com/newsroom/2025/12/john-giannandrea-to-retire-from-apple/
75•robbiet480•8h ago•286 comments

Instagram chief orders staff back to the office five days a week in 2026

https://www.businessinsider.com/instagram-chief-adam-mosseri-announces-five-day-office-return-202...
202•mfiguiere•9h ago•230 comments

The Penicillin Myth

https://www.asimov.press/p/penicillin-myth
157•surprisetalk•16h ago•80 comments

Shrinking While Linking

https://www.tweag.io/blog/2025-11-27-shrinking-static-libs/
7•ingve•4d ago•0 comments

Ask HN: Who wants to be hired? (December 2025)

123•whoishiring•14h ago•231 comments

Why I stopped using JSON for my APIs

https://aloisdeniel.com/blog/better-than-json
97•barremian•11h ago•116 comments

Durin is a library for reading and writing the Dwarf debugging format

https://github.com/tmcgilchrist/durin
64•mooreds•11h ago•16 comments