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

Async Rust never left the MVP state

https://tweedegolf.nl/en/blog/237/async-rust-never-left-the-mvp-state
238•pjmlp•5h ago•121 comments

Should I Run Plain Docker Compose in Production in 2026?

https://distr.sh/blog/running-docker-in-production/
106•pmig•4d ago•77 comments

Bun is being ported from Zig to Rust

https://github.com/oven-sh/bun/commit/46d3bc29f270fa881dd5730ef1549e88407701a5
581•SergeAx•11h ago•409 comments

When everyone has AI and the company still learns nothing

https://www.robert-glaser.de/when-everyone-has-ai-and-the-company-still-learns-nothing/
67•youngbrioche•2h ago•40 comments

Empty Screenings – Finds AMC movie screenings with few or no tickets sold

https://walzr.com/empty-screenings
186•MrBuddyCasino•7h ago•152 comments

Lessons for Agentic Coding: What should we do when code is cheap?

https://www.dbreunig.com/2026/05/04/10-lessons-for-agentic-coding.html
108•ingve•5h ago•84 comments

Hand Drawn QR Codes (2025)

https://sethmlarson.dev/hand-drawn-qr-codes
142•jollyjerry•8h ago•25 comments

Google Chrome silently installs a 4 GB AI model on your device without consent

https://www.thatprivacyguy.com/blog/chrome-silent-nano-install/
393•john-doe•4h ago•395 comments

sRGB profile comparison

https://ninedegreesbelow.com/photography/srgb-profile-comparison.html
6•Retr0id•2d ago•0 comments

How OpenAI delivers low-latency voice AI at scale

https://openai.com/index/delivering-low-latency-voice-ai-at-scale/
421•Sean-Der•16h ago•133 comments

Farewell to a Giant of Botany

https://nautil.us/farewell-to-a-giant-of-botany-1280409
48•Brajeshwar•2d ago•1 comments

CVE-2026-31431: Copy Fail vs. rootless containers

https://www.dragonsreach.it/2026/05/04/cve-2026-31431-copy-fail-rootless-containers/
125•averi•8h ago•60 comments

Train Your Own LLM from Scratch

https://github.com/angelos-p/llm-from-scratch
296•kristianpaul•8h ago•32 comments

Agent Skills

https://addyosmani.com/blog/agent-skills/
285•BOOSTERHIDROGEN•14h ago•139 comments

Mouse Pointer as a Mere Mortal

https://unsung.aresluna.org/mouse-pointer-as-a-mere-mortal/
42•zdw•2d ago•13 comments

The Frog for Whom the Bell Tolls

https://sethmlarson.dev/the-frog-for-whom-the-bell-tolls
22•anujbans•5h ago•7 comments

Why I Created phpc.tv

https://afilina.com/why-phpc-tv
30•luu•1d ago•5 comments

How Many Children Learned Mathematics from Kiselev's Textbooks?

https://valeman.medium.com/how-many-children-learned-mathematics-from-kiselevs-textbooks-ff4efcea...
35•ibobev•22h ago•5 comments

Today I've made the difficult decision to reduce the size of Coinbase by ~14%

https://twitter.com/brian_armstrong/status/2051616759145185723
18•adrianmsmith•19m ago•15 comments

Does Employment Slow Cognitive Decline? Evidence from Labor Market Shocks

https://www.nber.org/papers/w35117
309•littlexsparkee•20h ago•295 comments

Setting up server monitoring for a Rails app on Hatchbox

https://blog.appsignal.com/2026/04/30/setting-up-server-monitoring-for-a-rails-app-on-hatchbox.html
8•andreigaspar•1d ago•1 comments

Securing a DoD contractor: Finding a multi-tenant authorization vulnerability

https://www.strix.ai/blog/how-strix-found-zero-auth-vulnerability-dod-backed-startup
202•bearsyankees•18h ago•87 comments

Redis array: short story of a long development process

https://antirez.com/news/164
291•antirez•22h ago•105 comments

Biscuit

https://github.com/yattsu/biscuit
65•unixfg•9h ago•4 comments

2-D Mathematical Curves

https://www.2dcurves.com/
45•the-mitr•8h ago•3 comments

Formatting a 25M-line codebase overnight

https://stripe.dev/blog/formatting-an-entire-25-million-line-codebase-overnight-the-rubyfmt-story
182•r00k•16h ago•91 comments

When networking doesn't work

https://www.os2museum.com/wp/when-networking-doesnt-work/
73•kencausey•15h ago•11 comments

pgxbackup: Continuity Support for pgBackRest

https://thebuild.com/blog/2026/05/01/pgxbackup-continuity-support-for-pgbackrest/
61•Wingy•2d ago•10 comments

Talking to strangers at the gym

https://thienantran.com/talking-to-35-strangers-at-the-gym/
1393•thitran•1d ago•665 comments

Kids bypass age verification with fake moustaches

https://www.theregister.com/2026/05/04/uk_online_safety_act_age_checks_subvert/
138•dreadsword•7h ago•105 comments