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

Comments

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

Deploytarot.com – tarot card reading for deployments

https://deploytarot.com/setup
87•rembish•2h ago•20 comments

Why so many control rooms were seafoam green (2025)

https://bethmathews.substack.com/p/why-so-many-control-rooms-were-seafoam
461•Amorymeltzer•1d ago•83 comments

Cloudflare's Gen 13 servers: trading cache for cores for 2x performance

https://blog.cloudflare.com/gen13-launch/
51•wmf•3d ago•13 comments

DOOM Over DNS

https://github.com/resumex/doom-over-dns
168•Venn1•3d ago•53 comments

CERN to host a new phase of Open Research Europe

https://home.cern/news/news/cern/cern-host-europes-flagship-open-access-publishing-platform
162•JohnHammersley•3h ago•15 comments

My minute-by-minute response to the LiteLLM malware attack

https://futuresearch.ai/blog/litellm-attack-transcript/
257•Fibonar•7h ago•116 comments

New York City hospitals drop Palantir as controversial AI firm expands in UK

https://www.theguardian.com/technology/2026/mar/26/new-york-hospitals-palantir-ai
162•chrisjj•2h ago•57 comments

Show HN: Turbolite – a SQLite VFS serving sub-250ms cold JOIN queries from S3

https://github.com/russellromney/turbolite
90•russellthehippo•3h ago•24 comments

Moving from GitHub to Codeberg, for lazy people

https://unterwaditzer.net/2025/codeberg.html
481•jslakro•9h ago•244 comments

John Bradley, author of xv, has died

https://voxday.net/2026/03/25/rip-john-bradley/
172•linsomniac•4h ago•53 comments

OpenTelemetry profiles enters public alpha

https://opentelemetry.io/blog/2026/profiles-alpha/
132•tanelpoder•6h ago•14 comments

Anthropic Subprocessor Changes

https://trust.anthropic.com
11•tencentshill•1h ago•6 comments

Using FireWire on a Raspberry Pi

https://www.jeffgeerling.com/blog/2026/firewire-on-a-raspberry-pi/
33•jandeboevrie•2h ago•11 comments

We haven't seen the worst of what gambling and prediction markets will do

https://www.derekthompson.org/p/we-havent-seen-the-worst-of-what
447•mmcclure•3h ago•314 comments

HyperAgents: Self-referential self-improving agents

https://github.com/facebookresearch/hyperagents
102•andyg_blog•2d ago•45 comments

Personal Encyclopedias

https://whoami.wiki/blog/personal-encyclopedias
787•jrmyphlmn•1d ago•166 comments

How much precision can you squeeze out of a table?

https://www.johndcook.com/blog/2026/03/26/table-precision/
31•nomemory•3h ago•2 comments

Colibri – chat platform built on the AT Protocol for communities big and small

https://colibri.social/
94•todotask2•5h ago•49 comments

Show HN: Fio: 3D World editor/game engine – inspired by Radiant and Hammer

https://github.com/ViciousSquid/Fio
15•vicioussquid•1h ago•1 comments

Stripe Projects: Provision and manage services from the CLI

https://projects.dev/
91•piinbinary•6h ago•27 comments

Fast regex search: indexing text for agent tools

https://cursor.com/blog/fast-regex-search
19•jxmorris12•2d ago•4 comments

Non-Messing-Up++: Diagonal Sorting and Young Tableaux

https://winwang.blog/posts/non-messing-up++
6•winwang•3d ago•1 comments

From zero to a RAG system: successes and failures

https://en.andros.dev/blog/aa31d744/from-zero-to-a-rag-system-successes-and-failures/
269•andros•2d ago•79 comments

Running Tesla Model 3's computer on my desk using parts from crashed cars

https://bugs.xdavidhu.me/tesla/2026/03/23/running-tesla-model-3s-computer-on-my-desk-using-parts-...
839•driesdep•1d ago•294 comments

My home network observes bedtime with OpenBSD and pf

https://ratfactor.com/openbsd/pf-gateway-bedtime
106•ibobev•3d ago•31 comments

Iran oil revenue soars as it's the only exporter out of Hormuz

https://financialpost.com/commodities/energy/oil-gas/iran-oil-revenue-soars-hormuz
20•vrganj•1h ago•6 comments

Taming LLMs: Using Executable Oracles to Prevent Bad Code

https://john.regehr.org/writing/zero_dof_programming.html
26•mad44•5h ago•14 comments

Olympic Committee bars transgender athletes from women’s events

https://www.nytimes.com/2026/03/26/world/olympics/ioc-transgender-athletes-ban.html
209•RestlessMind•8h ago•484 comments

Building a Blog with Elixir and Phoenix

https://jola.dev/posts/building-a-blog-with-elixir-and-phoenix
67•shintoist•5h ago•5 comments

End of "Chat Control": EU parliament stops mass surveillance

https://www.patrick-breyer.de/en/end-of-chat-control-eu-parliament-stops-mass-surveillance-in-vot...
542•amarcheschi•10h ago•262 comments