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

Comments

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

Poland is now among the 20 largest economies. How it happened

https://apnews.com/article/poland-economy-growth-g20-gdp-26fe06e120398410f8d773ba5661e7aa
533•surprisetalk•3h ago•453 comments

Serving a Website on a Raspberry Pi Zero Running in RAM

https://btxx.org/posts/memory/
34•xngbuilds•56m ago•7 comments

An Introduction to Meshtastic

https://meshtastic.org/docs/introduction/
188•ColinWright•4h ago•69 comments

PC Engine CPU

https://jsgroth.dev/blog/posts/pc-engine-cpu/
46•ibobev•1h ago•5 comments

Google Cloud Fraud Defence is just WEI repackaged

https://privatecaptcha.com/blog/google-cloud-fraud-defence-wei/
59•ribtoks•2h ago•16 comments

Podman rootless containers and the Copy Fail exploit

https://garrido.io/notes/podman-rootless-containers-copy-fail/
40•ggpsv•2h ago•5 comments

Show HN: Git for AI Agents

https://github.com/regent-vcs/re_gent
23•doshay•1h ago•13 comments

Cloudflare to cut about 20% workforce

https://www.reuters.com/business/world-at-work/cloudflare-cut-over-1100-jobs-2026-05-07/
1099•PriorityLeft•19h ago•748 comments

Canvas online again as ShinyHunters threatens to leak schools’ data

https://www.theverge.com/tech/926458/canvas-shinyhunters-breach
846•stefanpie•17h ago•552 comments

GeoJSON

https://geojson.org/
93•tosh•6h ago•44 comments

Maybe you shouldn't install new software for a bit

https://xeiaso.net/blog/2026/abstain-from-install/
718•psxuaw•17h ago•384 comments

ClojureScript Gets Async/Await

https://clojurescript.org/news/2026-05-07-release
216•Borkdude•9h ago•53 comments

Rumors of my death are slightly exaggerated

791•CliffStoll•2d ago•107 comments

A web page that shows you everything the browser told it without asking

https://sinceyouarrived.world/taken
100•mwheelz•3h ago•58 comments

Dirtyfrag: Universal Linux LPE

https://www.openwall.com/lists/oss-security/2026/05/07/8
732•flipped•20h ago•304 comments

The map that keeps Burning Man honest

https://www.not-ship.com/burning-man-moop/
716•speckx•1d ago•334 comments

Pinocchio is weirder than you remembered

https://storica.club/blog/pinocchio-in-italian/
248•cemsakarya•2d ago•101 comments

Dithering with CSS

https://ikesau.co/blog/dithering-with-css/
88•speckx•4d ago•25 comments

Hackers breach JDownloader's website to serve malware-laced downloads

https://www.neowin.net/news/if-you-downloaded-this-popular-software-recently-you-might-have-insta...
70•bundie•3h ago•23 comments

Agents need control flow, not more prompts

https://bsuh.bearblog.dev/agents-need-control-flow/
548•bsuh•23h ago•265 comments

QBE – Compiler Back End

https://c9x.me/compile/
54•smartmic•9h ago•10 comments

Tesla is recalling its cheaper Cybertruck because the wheels might fall off

https://www.theverge.com/transportation/926741/tesla-cybertruck-cheaper-recall
133•droidjj•2h ago•128 comments

A polynomial autoencoder beats PCA on transformer embeddings

https://ivanpleshkov.dev/blog/polynomial-autoencoder/
80•timvisee•3d ago•22 comments

GPT-5.5 Price Increase: What It Costs

https://openrouter.ai/announcements/gpt55-cost-analysis
147•gmays•15h ago•38 comments

Brazil's Pix payment system faces pressure from Visa and Mastercard

https://www.elciudadano.com/en/brazils-pix-payment-system-faces-pressure-from-visa-and-mastercard...
333•wslh•22h ago•279 comments

Singapore introduces caning for boys who bully others at school

https://www.theguardian.com/world/2026/may/06/singapore-caning-school-bullies
288•rustoo•2d ago•421 comments

Nintendo announces price increases for Nintendo Switch 2

https://www.nintendo.co.jp/corporate/release/en/2026/260508.html
207•razorbeamz•9h ago•181 comments

Hardening Firefox with Claude Mythos Preview

https://hacks.mozilla.org/2026/05/behind-the-scenes-hardening-firefox/
298•HieronymusBosch•1d ago•132 comments

DeepSeek 4 Flash local inference engine for Metal

https://github.com/antirez/ds4
457•tamnd•1d ago•132 comments

Natural Language Autoencoders: Turning Claude's Thoughts into Text

https://www.anthropic.com/research/natural-language-autoencoders
345•instagraham•22h ago•108 comments