frontpage.
newsnewestaskshowjobs

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•1y ago

Comments

LegionMammal978•1y 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•1y 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•1y 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.

Inkling: Our Open-Weights Model

https://thinkingmachines.ai/news/introducing-inkling/
762•vimarsh6739•9h ago•194 comments

SQLite should have (Rust-style) editions

https://mort.coffee/home/sqlite-editions/
145•gnyeki•4h ago•59 comments

G# – A modern .NET language with Go, Kotlin, and Swift ergonomics

https://davidobando.github.io/gsharp/
49•serial_dev•4d ago•16 comments

Grok Build is open source

https://github.com/xai-org/grok-build
307•skp1995•7h ago•350 comments

Governments, companies, nonprofits should invest in free, open source AI [pdf]

https://www.siegelendowment.org/wp-content/uploads/2026/07/fortune-david-siegel-open-source-ai.pdf
110•bilsbie•6h ago•48 comments

Stripe and Advent have made a joint offer to acquire PayPal – sources

https://www.reuters.com/business/finance/stripe-advent-offer-buy-paypal-more-than-53-billion-sour...
382•rvz•1d ago•217 comments

Bluesky Trademarks ATProto

https://atproto.com/blog/at-protocol-trademark
19•chaosharmonic•2h ago•6 comments

The Tokio/Rayon Trap and Why Async/Await Fails Concurrency

https://pmbanugo.me/blog/why-async-await-complect-concurrency
7•LAC-Tech•1h ago•1 comments

LLM Networking with MikroTik

https://blog.greg.technology/2026/07/14/llm-networking-with-mikrotik.html
60•gregsadetsky•5h ago•24 comments

Metal-Organic Frameworks, Chemistry's New Miracle Materials (2018)

https://chemistry.berkeley.edu/news/meet-metal-organic-frameworks-chemistry%E2%80%99s-new-miracle...
43•andsoitis•4h ago•10 comments

CatchCat – Pokémon Go for Cats, IRL

https://www.catchcat.lol/
15•marojejian•5d ago•3 comments

Job queues are deceptively tricky

https://typesanitizer.com/blog/job-queues.html
39•ingve•1d ago•7 comments

Show HN: One More Letter

https://playonemoreletter.com/
55•hmate9•4h ago•31 comments

Running Gemma 4 26B at 5 tokens/sec on a 13-year-old Xeon with no GPU

https://www.neomindlabs.com/2026/06/08/running-gemma-4-26b-at-5-tokens-sec-on-a-13-year-old-xeon-...
251•neomindryan•12h ago•162 comments

Command Line Interface Guidelines

https://clig.dev/
86•subset•3d ago•16 comments

Duskers, the scary command line game, is getting a sequel

https://elbowgreasegames.substack.com/p/misfits-attic-announces-duskers-20
102•spacemarine1•8h ago•25 comments

Nul Characters in Strings in SQLite

https://sqlite.org/nulinstr.html
37•basilikum•4h ago•10 comments

Brainless: Shadcn components that look like Claude Code, Codex and Grok

https://brainless.swerdlow.dev
107•benswerd•7h ago•22 comments

Book prizes don't work how you think

https://rebeccamakkai.substack.com/p/book-prizes-dont-work-how-you-think
92•samclemens•1d ago•46 comments

Prioritize mental health, and why communication is so important

https://ramones.dev/posts/mental-health/
300•ramon156•16h ago•257 comments

Voxatron

https://www.lexaloffle.com/voxatron.php
73•lsferreira42•7h ago•19 comments

Mysteries of Telegram Data Centers (2022)

https://dev.moe/en/3025
246•theanonymousone•14h ago•132 comments

Collection of Digital Clock Designs

https://clocks.dev
195•levmiseri•11h ago•36 comments

P2P local file transfer based on WebRTC

https://pairdrop.net/
41•halb•5h ago•16 comments

Designing APIs for Agents

https://www.freestyle.sh/blog/opinion/designing-apis-for-agents
59•benswerd•2d ago•31 comments

Artie (YC S23) Is Hiring Software Engineers

https://jobs.ashbyhq.com/artie
1•tang8330•10h ago

Today I Rescued 7,234 Old GIFs

https://danq.me/2026/07/10/rescuing-7234-gifs/
117•birdculture•3d ago•12 comments

Towards a harness that can do anything

https://eardatasci.github.io/c/ambiance/index.html
180•evakhoury•13h ago•93 comments

Show HN: misa77 - a codec that decodes 2x faster than LZ4 (at better ratios)

https://github.com/welcome-to-the-sunny-side/misa77
135•nonadhocproblem•11h ago•40 comments

Show HN: Firefox in WebAssembly

https://developer.puter.com/labs/firefox-wasm/
150•coolelectronics•6h ago•86 comments