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•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.

Tony Hoare has died

https://blog.computationalcomplexity.org/2026/03/tony-hoare-1934-2026.html
1623•speckx•14h ago•212 comments

Zig – Type Resolution Redesign and Language Changes

https://ziglang.org/devlog/2026/#2026-03-10
89•Retro_Dev•3h ago•20 comments

U+237C ⍼ Is Azimuth

https://ionathan.ch/2026/02/16/angzarr.html
219•cokernel_hacker•6h ago•23 comments

Cloudflare crawl endpoint

https://developers.cloudflare.com/changelog/post/2026-03-10-br-crawl-endpoint/
199•jeffpalmer•6h ago•93 comments

Julia Snail – An Emacs Development Environment for Julia Like Clojure's Cider

https://github.com/gcv/julia-snail
28•TheWiggles•2d ago•1 comments

Agents that run while I sleep

https://www.claudecodecamp.com/p/i-m-building-agents-that-run-while-i-sleep
281•aray07•10h ago•257 comments

Writing my own text editor, and daily-driving it

https://blog.jsbarretto.com/post/text-editor
45•todsacerdoti•3h ago•9 comments

Yann LeCun raises $1B to build AI that understands the physical world

https://www.wired.com/story/yann-lecun-raises-dollar1-billion-to-build-ai-that-understands-the-ph...
394•helloplanets•20h ago•347 comments

SSH Secret Menu

https://twitter.com/rebane2001/status/2031037389347406054
119•piccirello•1d ago•41 comments

Launch HN: RunAnywhere (YC W26) – Faster AI Inference on Apple Silicon

https://github.com/RunanywhereAI/rcli
196•sanchitmonga22•12h ago•120 comments

Debian decides not to decide on AI-generated contributions

https://lwn.net/SubscriberLink/1061544/125f911834966dd0/
303•jwilk•14h ago•228 comments

Universal vaccine against respiratory infections and allergens

https://med.stanford.edu/news/all-news/2026/02/universal-vaccine.html
169•phony-account•6h ago•63 comments

Mesh over Bluetooth LE, TCP, or Reticulum

https://github.com/torlando-tech/columba
59•khimaros•10h ago•6 comments

FFmpeg-over-IP – Connect to remote FFmpeg servers

https://github.com/steelbrain/ffmpeg-over-ip
151•steelbrain•10h ago•53 comments

Invoker Commands API

https://developer.mozilla.org/en-US/docs/Web/API/Invoker_Commands_API
73•maqnius•2d ago•12 comments

Meta acquires Moltbook

https://www.axios.com/2026/03/10/meta-facebook-moltbook-agent-social-network
457•mmayberry•14h ago•297 comments

Intel Demos Chip to Compute with Encrypted Data

https://spectrum.ieee.org/fhe-intel
234•sohkamyung•16h ago•101 comments

Bippy: React Internals Toolkit

https://www.bippy.dev/
29•handfuloflight•2d ago•6 comments

Launch HN: Didit (YC W26) – Stripe for Identity Verification

60•rosasalberto•14h ago•54 comments

EQT eyes potential $6B sale of Linux pioneer SUSE, sources say

https://www.reuters.com/business/eqt-eyes-potential-6-billion-sale-linux-pioneer-suse-sources-say...
32•shscs911•1d ago•8 comments

Roblox is minting teen millionaires

https://www.bloomberg.com/news/articles/2026-03-06/roblox-s-teen-millionaires-are-disrupting-the-...
95•petethomas•3d ago•93 comments

Show HN: How I topped the HuggingFace open LLM leaderboard on two gaming GPUs

https://dnhkng.github.io/posts/rys/
349•dnhkng•16h ago•94 comments

Exploring the ocean with Raspberry Pi–powered marine robots

https://www.raspberrypi.com/news/exploring-the-ocean-with-raspberry-pi-powered-marine-robots/
66•Brajeshwar•3d ago•8 comments

Rebasing in Magit

https://entropicthoughts.com/rebasing-in-magit
196•ibobev•15h ago•131 comments

Traditional tales from Cornwall, with maps for stories' locations

https://www.mazedtales.org/
8•ohjeez•3d ago•0 comments

After outages, Amazon to make senior engineers sign off on AI-assisted changes

https://arstechnica.com/ai/2026/03/after-outages-amazon-to-make-senior-engineers-sign-off-on-ai-a...
507•ndr42•15h ago•412 comments

Open Weights isn't Open Training

https://www.workshoplabs.ai/blog/open-weights-open-training
91•addiefoote8•1d ago•28 comments

Mother of All Grease Fires (1994)

https://milk.com/wall-o-shame/bucket.html
50•xk3•9h ago•18 comments

Show HN: Safelaunch – Validates your environment before you push to production

https://www.npmjs.com/package/safelaunch
6•karthicedricq•3d ago•1 comments

Tell HN: Apple development certificate server seems down?

81•strongpigeon•9h ago•32 comments