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

Why Japanese companies do so many different things

https://davidoks.blog/p/why-japanese-companies-do-so-many
315•d0ks•4h ago•179 comments

U.S. researchers face new restrictions on publishing with foreign collaborators

https://www.science.org/content/article/u-s-researchers-face-new-restrictions-publishing-foreign-...
188•ceejayoz•3h ago•104 comments

Open source Kanban desktop app that runs parallel agents on every card

https://www.kanbots.dev/
47•vitriapp•1h ago•19 comments

A scoping review of bicycling interventions’ impacts on well-being

https://www.frontiersin.org/journals/sports-and-active-living/articles/10.3389/fspor.2026.1807791...
27•gnabgib•1h ago•10 comments

Project Glasswing: An Initial Update

https://www.anthropic.com/research/glasswing-initial-update
6•louiereederson•13m ago•1 comments

Deno 2.8

https://deno.com/blog/v2.8
215•roflcopter69•8h ago•98 comments

1940 Air Terminal Museum Begins Liquidation

https://www.1940airterminal.org/news/liquidation-of-simulators
35•weaponeer•2h ago•11 comments

Antigravity 2.0 Tops the OpenSCAD Architectural 3D LLM Benchmark

https://modelrift.com/blog/openscad-llm-benchmark/
303•jetter•9h ago•116 comments

Bun support is now limited and deprecated

https://github.com/yt-dlp/yt-dlp/issues/16766
180•tamnd•2h ago•125 comments

Bun's unreleased Rust port has 13,365 unsafe blocks

https://bun.com/bun-unsafe-audit
12•helloplanets•58m ago•1 comments

A Forth-inspired language for writing websites

https://robida.net/entries/2026/05/21/a-forth-inspired-language-for-writing-websites
71•speckx•4h ago•8 comments

Launch HN: Superset (YC P26) – IDE for the agents era

https://github.com/superset-sh/superset
52•avipeltz•4h ago•68 comments

Lawmakers Demand Answers as CISA Tries to Contain Data Leak

https://krebsonsecurity.com/2026/05/lawmakers-demand-answers-as-cisa-tries-to-contain-data-leak/
31•speckx•2h ago•1 comments

If you’re an LLM, please read this

https://annas-archive.gl/blog/llms-txt.html
619•janandonly•8h ago•369 comments

Microsoft starts canceling Claude Code licenses

https://www.theverge.com/tech/930447/microsoft-claude-code-discontinued-notepad
88•robertkarl•2h ago•46 comments

Built AI forensic accounting software with my dad

https://case-trail.com/blog/ai-forensic-accounting-automation
47•mstalcup•3h ago•29 comments

DeepSeek makes the V4 Pro price discount permanent

https://api-docs.deepseek.com/quick_start/pricing
148•Tiberium•3h ago•71 comments

USCIS Will Grant 'Adjustment of Status' Only in Extraordinary Circumstances

https://www.uscis.gov/newsroom/news-releases/us-citizenship-and-immigration-services-will-grant-a...
15•arrowleaf•20m ago•2 comments

TorQ: Kdb+ Production Framework

https://github.com/DataIntellectTech/TorQ
9•tosh•2h ago•1 comments

Circle Medical (YC S15) Is Hiring a Mobile Engineer

https://www.ycombinator.com/companies/circle-medical/jobs/onMKAG9-mobile-engineer-android
1•jboula•7h ago

Robert X Cringely is back to blogging

https://www.cringely.com/
15•dan_hawkins•5h ago•0 comments

Domain-Camouflaged Injection Attacks Evade Detection in Multi-Agent LLM Systems

https://arxiv.org/abs/2605.22001
5•sbulaev•59m ago•0 comments

Project Hail Mary – Stellar Navigation Chart

https://valhovey.github.io/gaia-mary/
1092•speleo•1d ago•222 comments

Show HN: ShadowCat – file transfer through QR Codes in a Browser

https://github.com/unprovable/ShadowCat
114•unprovable•8h ago•42 comments

How to convert between wealth and income tax

https://paulgraham.com/winc.html
86•bifftastic•4h ago•270 comments

The memory shortage is causing a repricing of consumer electronics

https://davidoks.blog/p/ai-is-killing-the-cheap-smartphone
414•d0ks•21h ago•507 comments

AI has a multiplying effect on existing technical skills

https://www.joshwcomeau.com/email/wham-launch-005-elephant-2-p/
221•moebrowne•6h ago•223 comments

Chess invariants

http://muratbuffalo.blogspot.com/2026/05/chess-invariants.html
73•ingve•8h ago•45 comments

Cleve Moler has died

https://www.mathworks.com/company/aboutus/founders/clevemoler.html
245•mychele•17h ago•24 comments

Slumber a TUI HTTP Client

https://slumber.lucaspickering.me
155•jicea•15h ago•56 comments