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

Comments

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

Plasma Bigscreen – 10-foot interface for KDE plasma

https://plasma-bigscreen.org
443•PaulHoule•10h ago•126 comments

Show HN: Tanstaafl – Pay-to-inbox email on Bitcoin Lightning

https://tanstaafl.email
4•NikoBlack•23m ago•1 comments

Tell HN: I'm 60 years old. Claude Code has re-ignited a passion

467•shannoncc•10h ago•333 comments

UUID package coming to Go standard library

https://github.com/golang/go/issues/62026
203•soypat•8h ago•112 comments

QGIS 4.0

https://changelog.qgis.org/en/version/4.0/
56•jonbaer•1h ago•5 comments

this css proves me human

https://will-keleher.com/posts/this-css-makes-me-human/
269•todsacerdoti•12h ago•89 comments

Working and Communicating with Japanese Engineers

https://www.tokyodev.com/articles/working-and-communicating-with-japanese-engineers
30•zdw•3d ago•12 comments

Helix: A post-modern text editor

https://helix-editor.com/
158•doener•10h ago•59 comments

Galileo's handwritten notes found in ancient astronomy text

https://www.science.org/content/article/galileo-s-handwritten-notes-found-ancient-astronomy-text
137•tzury•1d ago•26 comments

LLMs work best when the user defines their acceptance criteria first

https://blog.katanaquant.com/p/your-llm-doesnt-write-correct-code
235•dnw•9h ago•181 comments

Lock Scroll with a Vengeance

https://unsung.aresluna.org/lock-scroll-with-a-vengeance/
13•etothet•3d ago•2 comments

Uploading Pirated Books via BitTorrent Qualifies as Fair Use, Meta Argues

https://torrentfreak.com/uploading-pirated-books-via-bittorrent-qualifies-as-fair-use-meta/
21•askl•1h ago•8 comments

Sarvam 105B, the first competitive Indian open source LLM

https://www.sarvam.ai/blogs/sarvam-30b-105b
54•logicchains•3h ago•7 comments

Show HN: Moongate – Ultima Online server emulator in .NET 10 with Lua scripting

https://github.com/moongate-community/moongatev2
257•squidleon•20h ago•141 comments

Claude AI Helped Bomb Iran. But How Exactly?

https://www.bloomberg.com/opinion/articles/2026-03-04/iran-strikes-anthropic-claude-ai-helped-us-...
9•helsinkiandrew•36m ago•2 comments

Querying 3B Vectors

https://vickiboykis.com/2026/02/21/querying-3-billion-vectors/
51•surprisetalk•3d ago•6 comments

Modernizing swapping: virtual swap spaces

https://lwn.net/Articles/1059201/
28•voxadam•1d ago•18 comments

The Longing (1999)

https://www.cluetrain.com/book/longing.html
22•herbertl•3d ago•1 comments

What canceled my Go context?

https://rednafi.com/go/context-cancellation-cause/
64•mweibel•3d ago•36 comments

My application programmer instincts failed when debugging assembler

https://landedstar.com/blog/posts/how-my-application-programmer-instincts-failed-when-debugging-a...
11•lifefeed•1d ago•9 comments

Editing changes in patch format with Jujutsu

https://www.knifepoint.net/~kat/kb-jj-patchedit.html
27•cassepipe•2d ago•5 comments

Maybe there's a pattern here?

https://dynomight.net/pattern/
129•surprisetalk•2d ago•79 comments

From Fargo to Zebra

https://cendyne.dev/posts/2026-02-27-from-fargo-to-zebra.html
3•surprisetalk•3d ago•0 comments

Tech employment now significantly worse than the 2008 or 2020 recessions

https://twitter.com/JosephPolitano/status/2029916364664611242
898•enraged_camel•17h ago•597 comments

Show HN: Kula – Lightweight, self-contained Linux server monitoring tool

https://github.com/c0m4r/kula
57•c0m4r•10h ago•29 comments

CT Scans of Health Wearables

https://www.lumafield.com/scan-of-the-month/health-wearables
219•radeeyate•20h ago•47 comments

Launch HN: Palus Finance (YC W26): Better yields on idle cash for startups, SMBs

52•sam_palus•16h ago•76 comments

Entomologists use a particle accelerator to image ants at scale

https://spectrum.ieee.org/3d-scanning-particle-accelerator-antscan
129•gmays•18h ago•24 comments

Hardening Firefox with Anthropic's Red Team

https://www.anthropic.com/news/mozilla-firefox-security
569•todsacerdoti•22h ago•156 comments

C# strings silently kill your SQL Server indexes in Dapper

https://consultwithgriff.com/dapper-nvarchar-implicit-conversion-performance-trap
103•PretzelFisch•11h ago•74 comments