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

Arm AGI CPU

https://newsroom.arm.com/blog/introducing-arm-agi-cpu
131•RealityVoid•2h ago•65 comments

Apple Business

https://www.apple.com/newsroom/2026/03/introducing-apple-business-a-new-all-in-one-platform-for-b...
234•soheilpro•4h ago•180 comments

Hypura – A storage-tier-aware LLM inference scheduler for Apple Silicon

https://github.com/t8/hypura
147•tatef•3h ago•63 comments

Tell HN: Litellm 1.82.7 and 1.82.8 on PyPI are compromised

https://github.com/BerriAI/litellm/issues/24512
178•dot_treo•7h ago•310 comments

No Terms. No Conditions

https://notermsnoconditions.com
172•bayneri•3h ago•69 comments

ARM AGI CPU: Specs and SKUs

https://sbcwiki.com/docs/soc-manufacturers/arm/arm-silicon/
69•HeyMeco•1h ago•15 comments

Hypothesis, Antithesis, synthesis

https://antithesis.com/blog/2026/hegel/
131•alpaylan•4h ago•58 comments

Wine 11 rewrites how Linux runs Windows games at kernel with massive speed gains

https://www.xda-developers.com/wine-11-rewrites-linux-runs-windows-games-speed-gains/
139•felineflock•1h ago•21 comments

Show HN: Email.md – Markdown to responsive, email-safe HTML

https://www.emailmd.dev/
85•dancablam•3h ago•24 comments

Show HN: Gemini can now natively embed video, so I built sub-second video search

https://github.com/ssrajadh/sentrysearch
135•sohamrj•4h ago•42 comments

Epic Games to cut more than 1k jobs as Fortnite usage falls

https://www.reuters.com/legal/litigation/epic-games-said-tuesday-that-it-will-lay-off-more-than-1...
29•doughnutstracks•4h ago•77 comments

LaGuardia pilots raised safety alarms months before deadly runway crash

https://www.theguardian.com/us-news/2026/mar/24/laguardia-airplane-pilots-safety-concerns-crash
242•m_fayer•4h ago•194 comments

Show HN: Gridland: make terminal apps that also run in the browser

https://www.gridland.io/
11•rothific•2h ago•0 comments

Missile defense is NP-complete

https://smu160.github.io/posts/missile-defense-is-np-complete/
172•O3marchnative•6h ago•215 comments

Data Manipulation in Clojure Compared to R and Python

https://codewithkira.com/2024-07-18-tablecloth-dplyr-pandas-polars.html
39•tosh•2d ago•8 comments

Nanobrew: The fastest macOS package manager compatible with brew

https://nanobrew.trilok.ai/
132•syrusakbary•8h ago•84 comments

Testing the Swift C compatibility with Raylib (+WASM)

https://carette.xyz/posts/swift_c_compatibility_with_raylib/
45•LucidLynx•2d ago•16 comments

WolfGuard: WireGuard with FIPS 140-3 cryptography

https://github.com/wolfssl/wolfguard
55•789c789c789c•3h ago•41 comments

Microsoft's "fix" for Windows 11

https://www.sambent.com/microsofts-plan-to-fix-windows-11-is-gaslighting/
837•h0ek•10h ago•615 comments

Show HN: ProofShot – Give AI coding agents eyes to verify the UI they build

https://github.com/AmElmo/proofshot
85•jberthom•11h ago•61 comments

Tony Hoare and His Imprint on Computer Science

https://cacm.acm.org/blogcacm/tony-hoare-and-his-imprint-on-computer-science/
48•matt_d•3d ago•4 comments

Debunking Zswap and Zram Myths

https://chrisdown.name/2026/03/24/zswap-vs-zram-when-to-use-what.html
153•javierhonduco•9h ago•43 comments

Ripgrep is faster than grep, ag, git grep, ucg, pt, sift (2016)

https://burntsushi.net/ripgrep/
282•jxmorris12•13h ago•123 comments

I quit editing photos

https://jamesbaker.uk/i-quit-editing-photos/
64•speckx•3d ago•93 comments

Overcoming the friendship recession

https://joeprevite.com/friendship-recession/
69•surprisetalk•4d ago•65 comments

So where are all the AI apps?

https://www.answer.ai/posts/2026-03-12-so-where-are-all-the-ai-apps.html
330•tanelpoder•5h ago•305 comments

How to use storytelling to fit inline assembly into Rust

https://www.ralfj.de/blog/2026/03/13/inline-asm.html
8•vinhnx•2d ago•0 comments

curl > /dev/sda: How I made a Linux distro that runs wget | dd

https://astrid.tech/2026/03/24/0/curl-to-dev-sda/
130•astralbijection•9h ago•54 comments

Secure Domain Name System (DNS) Deployment 2026 Guide [pdf]

https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-81r3.pdf
80•XzetaU8•7h ago•8 comments

io_uring, libaio performance across Linux kernels and an unexpected IOMMU trap

https://blog.ydb.tech/how-io-uring-overtook-libaio-performance-across-linux-kernels-and-an-unexpe...
52•tanelpoder•6h ago•16 comments