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.

F-Droid: "Keep Android Open"

https://f-droid.org/2026/02/20/twif.html
77•LorenDB•17m ago•7 comments

Ggml.ai joins Hugging Face to ensure the long-term progress of Local AI

https://github.com/ggml-org/llama.cpp/discussions/19759
437•lairv•4h ago•97 comments

I found a useful Git one liner buried in leaked CIA developer docs

https://spencer.wtf/2026/02/20/cleaning-up-merged-git-branches-a-one-liner-from-the-cias-leaked-d...
372•spencerldixon•4h ago•159 comments

Child's Play: Tech's new generation and the end of thinking

https://harpers.org/archive/2026/03/childs-play-sam-kriss-ai-startup-roy-lee/
173•ramimac•3h ago•101 comments

The path to ubiquitous AI (17k tokens/sec)

https://taalas.com/the-path-to-ubiquitous-ai/
518•sidnarsipur•7h ago•323 comments

Trump's global tariffs struck down by US Supreme Court

https://www.bbc.com/news/live/c0l9r67drg7t
664•blackguardx•2h ago•512 comments

Untapped Way to Learn a Codebase: Build a Visualizer

https://jimmyhmiller.com/learn-codebase-visualizer
140•andreabergia•9h ago•22 comments

Legion Health (YC) Is Hiring Cracked SWEs for Autonomous Mental Health

https://jobs.ashbyhq.com/legionhealth/ffdd2b52-eb21-489e-b124-3c0804231424
1•ympatel•1h ago

Lil' Fun Langs

https://taylor.town/scrapscript-000
5•surprisetalk•42m ago•0 comments

PayPal discloses data breach that exposed user info for 6 months

https://www.bleepingcomputer.com/news/security/paypal-discloses-data-breach-exposing-users-person...
155•el_duderino•4h ago•46 comments

The Rediscovery of 103 Hokusai Lost Sketches (2021)

https://japan-forward.com/eternal-hokusai-the-rediscovery-of-103-hokusai-lost-sketches/
41•debo_•4d ago•2 comments

Minions – Stripe's Coding Agents Part 2

https://stripe.dev/blog/minions-stripes-one-shot-end-to-end-coding-agents-part-2
102•ludovicianul•6h ago•52 comments

The Popper Principle

https://theamericanscholar.org/the-popper-principle/
25•lermontov•1d ago•10 comments

Show HN: A native macOS client for Hacker News, built with SwiftUI

https://github.com/IronsideXXVI/Hacker-News
107•IronsideXXVI•4h ago•58 comments

Visible Spectra of the Elements

https://atomic-spectra.net/
17•djoldman•3d ago•1 comments

Raspberry Pi Pico 2 at 873.5MHz with 3.05V Core Abuse

https://learn.pimoroni.com/article/overclocking-the-pico-2
98•Lwrless•9h ago•27 comments

No Skill. No Taste

https://blog.kinglycrow.com/no-skill-no-taste/
90•ianbutler•2h ago•97 comments

Web Components: The Framework-Free Renaissance

https://www.caimito.net/en/blog/2026/02/17/web-components-the-framework-free-renaissance.html
146•mpweiher•9h ago•95 comments

Consistency diffusion language models: Up to 14x faster, no quality loss

https://www.together.ai/blog/consistency-diffusion-language-models
178•zagwdt•14h ago•75 comments

AI is not a coworker, it's an exoskeleton

https://www.kasava.dev/blog/ai-as-exoskeleton
437•benbeingbin•22h ago•426 comments

Lessons learned from `oapi-codegen`'s time in the GitHub Secure Open Source Fund

https://www.jvt.me/posts/2026/02/17/oapi-codegen-github-secure/
5•zdw•2d ago•0 comments

Infrastructure decisions I endorse or regret after 4 years at a startup (2024)

https://cep.dev/posts/every-infrastructure-decision-i-endorse-or-regret-after-4-years-running-inf...
420•Meetvelde•3d ago•187 comments

Reading the undocumented MEMS accelerometer on Apple Silicon MacBooks via iokit

https://github.com/olvvier/apple-silicon-accelerometer
114•todsacerdoti•13h ago•53 comments

Notes on Clarifying Man Pages

https://jvns.ca/blog/2026/02/18/man-pages/
45•surprisetalk•1d ago•31 comments

US plans online portal to bypass content bans in Europe and elsewhere

https://www.reuters.com/world/us-plans-online-portal-bypass-content-bans-europe-elsewhere-2026-02...
426•c420•1d ago•810 comments

Show HN: Micasa – track your house from the terminal

https://micasa.dev
608•cpcloud•1d ago•193 comments

Tesla to pay $243M judgement over Autopilot crash

https://electrek.co/2026/02/20/tesla-has-to-pay-historical-243-million-judgement-over-autopilot-c...
16•jeffbee•1h ago•2 comments

FreeCAD

https://www.freecad.org/index.php
354•doener•3d ago•153 comments

A beginner's guide to split keyboards

https://www.justinmklam.com/posts/2026/02/beginners-guide-split-keyboards/
217•thehaikuza•4d ago•227 comments

I tried building my startup entirely on European infrastructure

https://www.coinerella.com/made-in-eu-it-was-harder-than-i-thought/
632•willy__•9h ago•322 comments