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.

At least 50 hallucinated citations found in ICLR 2026 submissions

https://gptzero.me/news/iclr-2026/
303•puttycat•4h ago•222 comments

Google Titans architecture, helping AI have long-term memory

https://research.google/blog/titans-miras-helping-ai-have-long-term-memory/
185•Alifatisk•5h ago•70 comments

Scala 3 slowed us down?

https://kmaliszewski9.github.io/scala/2025/12/07/scala3-slowdown.html
72•kmaliszewski•2h ago•24 comments

I Tried and Failed to Rebuild the 1996 Space Jam Website with Claude

https://j0nah.com/i-failed-to-recreate-the-1996-space-jam-website-with-claude/
13•thecr0w•46m ago•6 comments

Goodbye, Microsoft: Schleswig-Holstein Relies on Open Source and Saves Millions

https://www.heise.de/en/news/Goodbye-Microsoft-Schleswig-Holstein-relies-on-Open-Source-and-saves...
354•doener•4h ago•172 comments

Java Hello World, LLVM Edition

https://www.javaadvent.com/2025/12/java-hello-world-llvm-edition.html
122•ingve•6h ago•36 comments

The Anatomy of a macOS App

https://eclecticlight.co/2025/12/04/the-anatomy-of-a-macos-app/
93•elashri•5h ago•20 comments

An Interactive Guide to the Fourier Transform

https://betterexplained.com/articles/an-interactive-guide-to-the-fourier-transform/
19•pykello•5d ago•3 comments

Using LLMs at Oxide

https://rfd.shared.oxide.computer/rfd/0576
575•steveklabnik•16h ago•224 comments

Kilauea erupts, destroying webcam [video]

https://www.youtube.com/watch?v=TK2N99BDw7A
490•zdw•18h ago•109 comments

How the Disappearance of Flight 19 Fueled the Legend of the Bermuda Triangle

https://www.smithsonianmag.com/history/how-the-disappearance-of-flight-19-a-navy-squadron-lost-in...
32•pseudolus•5h ago•3 comments

Building a Toast Component

https://emilkowal.ski/ui/building-a-toast-component
39•FragrantRiver•4d ago•17 comments

Z2 – Lithographically fabricated IC in a garage fab

https://sam.zeloof.xyz/second-ic/
281•embedding-shape•15h ago•62 comments

GrapheneOS is the only Android OS providing full security patches

https://grapheneos.social/@GrapheneOS/115647408229616018
709•akyuu•1d ago•327 comments

Screenshots from developers: 2002 vs. 2015 (2015)

https://anders.unix.se/2015/12/10/screenshots-from-developers--2002-vs.-2015/
404•turrini•20h ago•167 comments

The AI Wildfire Is Coming. It's Going to Be Painful and Healthy

https://ceodinner.substack.com/p/the-ai-wildfire-is-coming-its-going
16•LordAtlas•1h ago•10 comments

The past was not that cute

https://juliawise.net/the-past-was-not-that-cute/
330•mhb•20h ago•410 comments

Locks in PostgreSQL

https://habr.com/en/companies/postgrespro/articles/504498/
39•fanf2•2h ago•3 comments

The programmers who live in Flatland

https://blog.redplanetlabs.com/2025/11/24/the-programmers-who-live-in-flatland/
35•winkywooster•1w ago•28 comments

OpenAI disables ChatGPT app suggestions that looked like ads

https://techoreon.com/openai-disables-chatgpt-app-suggestions-ads-backlash/
35•GeorgeWoff25•2h ago•17 comments

Discovering the indieweb with calm tech

https://alexsci.com/blog/calm-tech-discover/
166•todsacerdoti•14h ago•17 comments

What even is "literate programming"? (2024)

https://pqnelson.github.io/2024/05/29/literate-programming.html
56•joecobb•4d ago•31 comments

Tiny Core Linux: a 23 MB Linux distro with graphical desktop

http://www.tinycorelinux.net/
483•LorenDB•1d ago•214 comments

Perl's decline was cultural

https://www.beatworm.co.uk/blog/computers/perls-decline-was-cultural-not-technical
333•todsacerdoti•1d ago•378 comments

Eurydice: a Rust to C compiler (yes)

https://jonathan.protzenko.fr/2025/10/28/eurydice.html
159•todsacerdoti•16h ago•87 comments

Z-Image: Powerful and highly efficient image generation model with 6B parameters

https://github.com/Tongyi-MAI/Z-Image
353•doener•1w ago•141 comments

Patching Pulse Oximeter Firmware

https://stefan-gloor.ch/pulseoximeter-hack
36•stgl•6d ago•5 comments

Martin Parr has died

https://www.bbc.co.uk/news/articles/cg5m0mnvnvmo
34•yzydserd•2h ago•2 comments

Bikeshedding, or why I want to build a laptop

https://geohot.github.io//blog/jekyll/update/2025/11/29/bikeshedding-or-laptop.html
189•cspags•6d ago•206 comments

HTML as an Accessible Format for Papers (2023)

https://info.arxiv.org/about/accessible_HTML.html
256•el3ctron•1d ago•123 comments