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.

I Forked Httpx

https://tildeweb.nl/~michiel/httpxyz.html
58•roywashere•1h ago•28 comments

TurboQuant: Redefining AI efficiency with extreme compression

https://research.google/blog/turboquant-redefining-ai-efficiency-with-extreme-compression/
143•ray__•4h ago•27 comments

VitruvianOS – Desktop Linux Inspired by the BeOS

https://v-os.dev
131•felixding•6h ago•65 comments

Goodbye to Sora

https://twitter.com/soraofficialapp/status/2036532795984715896
700•mikeocool•13h ago•505 comments

Flighty Airports

https://flighty.com/airports
311•skogstokig•8h ago•102 comments

Show HN: I took back Video.js after 16 years and we rewrote it to be 88% smaller

https://videojs.org/blog/videojs-v10-beta-hello-world-again
396•Heff•15h ago•74 comments

Tell HN: Litellm 1.82.7 and 1.82.8 on PyPI are compromised

https://github.com/BerriAI/litellm/issues/24512
669•dot_treo•21h ago•420 comments

Apple Business

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

I wanted to build vertical SaaS for pest control, so I took a technician job

https://www.onhand.pro/p/i-wanted-to-build-vertical-saas-for-pest-control-i-took-a-technician-job...
293•tezclarke•12h ago•122 comments

You can run a DNS server (2025)

https://simonsafar.com/2025/running_dns/
73•surprisetalk•4d ago•37 comments

Arm AGI CPU

https://newsroom.arm.com/blog/introducing-arm-agi-cpu
342•RealityVoid•15h ago•257 comments

Fun with CSF firmware (RK3588 GPU firmware)

https://icecream95.gitlab.io/fun-with-csf-firmware.html
26•M95D•3d ago•0 comments

Show HN: DuckDB community extension for prefiltered HNSW using ACORN-1

https://github.com/cigrainger/duckdb-hnsw-acorn
45•cigrainger•6h ago•3 comments

Algorithm Visualizer

https://algorithm-visualizer.org/
91•vinhnx•4d ago•5 comments

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

https://www.emailmd.dev/
288•dancablam•17h ago•68 comments

VNDB founder Yorhel has died

https://vndb.org/t24787
23•indrora•2d ago•7 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/
922•felineflock•14h ago•329 comments

A Compiler Writing Journey

https://github.com/DoctorWkt/acwj
78•ibobev•9h ago•7 comments

The Last Testaments of Richard II and Henry IV

https://www.historytoday.com/archive/feature/last-testaments-richard-ii-and-henry-iv
4•Petiver•3d ago•0 comments

Intel Device Modeling Language for virtual platforms

https://github.com/intel/device-modeling-language
28•transpute•4d ago•0 comments

An Aural Companion for Decades, CBS News Radio Crackles to a Close

https://www.nytimes.com/2026/03/21/business/media/cbs-news-radio-appraisal.html
55•tintinnabula•3d ago•13 comments

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

https://github.com/ssrajadh/sentrysearch
325•sohamrj•18h ago•90 comments

Hypothesis, Antithesis, synthesis

https://antithesis.com/blog/2026/hegel/
250•alpaylan•18h ago•85 comments

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

https://github.com/t8/hypura
204•tatef•17h ago•76 comments

Missile defense is NP-complete

https://smu160.github.io/posts/missile-defense-is-np-complete/
336•O3marchnative•20h ago•337 comments

What happened to GEM?

https://dfarq.homeip.net/whatever-happened-to-gem/
76•naves•4d ago•40 comments

Implementing automatic eSIM installation on Android

https://medium.com/proandroiddev/integration-of-automatic-esim-installation-on-android-6c5f6d7124cb
25•nesterenkopavel•3h ago•5 comments

How the world’s first electric grid was built

https://worksinprogress.co/issue/how-the-worlds-first-electric-grid-was-built/
88•zdw•4d ago•27 comments

Nanobrew: The fastest macOS package manager compatible with brew

https://nanobrew.trilok.ai/
210•syrusakbary•21h ago•126 comments

The final switch: Goldsboro, 1961

https://blog.nuclearsecrecy.com/2013/09/27/final-switch-goldsboro-1961/
13•1970-01-01•3d ago•2 comments