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.

OpenCode – The open source AI coding agent

https://opencode.ai/
290•rbanffy•2h ago•134 comments

Our commitment to Windows quality

https://blogs.windows.com/windows-insider/2026/03/20/our-commitment-to-windows-quality/
311•hadrien01•4h ago•557 comments

Discontinuation and reinitiation of dual-labeled GLP-1 receptor agonists

https://nautil.us/whiplash-heart-attack-and-stroke-risk-jumps-when-people-stop-taking-glp-1s-1279029
45•siquick•2h ago•36 comments

We rewrote our Rust WASM Parser in TypeScript – and it got 3x Faster

https://www.openui.com/blog/rust-wasm-parser
55•zahlekhan•2h ago•23 comments

I love my dumb watches

https://gary.onl/a-post-about-watches/
47•abnercoimbre•3d ago•36 comments

France's aircraft carrier located in real time by Le Monde through fitness app

https://www.lemonde.fr/en/international/article/2026/03/20/stravaleaks-france-s-aircraft-carrier-...
441•MrDresden•10h ago•372 comments

Show HN: We built a terminal-only Bluesky / AT Proto client written in Fortran

https://github.com/FormerLab/fortransky
23•FormerLabFred•1h ago•23 comments

Ghostling

https://github.com/ghostty-org/ghostling
25•bjornroberg•1h ago•4 comments

Attention Residuals

https://github.com/MoonshotAI/Attention-Residuals
105•GaggiX•5h ago•18 comments

An FAQ on Reinforcement Learning Environments

https://epoch.ai/gradient-updates/state-of-rl-envs
6•dcre•1d ago•0 comments

Show HN: Baltic shadow fleet tracker – live AIS, cable proximity alerts

https://github.com/FormerLab/shadow-fleet-tracker-light
20•FormerLabFred•2h ago•5 comments

The Los Angeles Aqueduct Is Wild

https://practical.engineering/blog/2026/3/17/the-los-angeles-aqueduct-is-wild
274•michaefe•3d ago•155 comments

Show HN: Red Grid Link – peer-to-peer team tracking over Bluetooth, no servers

https://github.com/RedGridTactical/RedGridLink
8•redgridtactical•1h ago•3 comments

Show HN: I made an email app inspired by Arc browser

https://demo.define.app
39•johndamaia•5h ago•20 comments

VisiCalc Reconstructed

https://zserge.com/posts/visicalc/
151•ingve•3d ago•64 comments

Work_mem: It's a Trap

https://mydbanotebook.org/posts/work_mem-its-a-trap/
23•enz•2d ago•2 comments

NumKong: 2'000 Mixed Precision Kernels for All

https://ashvardanian.com/posts/numkong/
22•ashvardanian•4h ago•0 comments

Parallel Perl – Autoparallelizing interpreter with JIT

https://perl.petamem.com/gpw2026/perl-mit-ai-gpw2026.html#/4/1/1
94•bmn__•2d ago•35 comments

A Japanese Glossary of Chopsticks Faux Pas

https://www.nippon.com/en/japan-data/h01362/
82•cainxinth•2h ago•78 comments

Delve – Fake Compliance as a Service

https://deepdelver.substack.com/p/delve-fake-compliance-as-a-service
506•freddykruger•1d ago•180 comments

The worst volume control UI in the world (2017)

https://uxdesign.cc/the-worst-volume-control-ui-in-the-world-60713dc86950
48•andsoitis•2d ago•26 comments

Entso-E final report on Iberian 2025 blackout

https://www.entsoe.eu/publications/blackout/28-april-2025-iberian-blackout/
169•Rygian•12h ago•72 comments

Meme Buildings

https://misfitsarchitecture.com/2026/03/15/meme-buildings/
15•speckx•7h ago•1 comments

The Social Smolnet

https://ploum.net/2026-03-20-social-smolnet.html
103•aebtebeten•10h ago•11 comments

Launch HN: Sitefire (YC W26) – Automating actions to improve AI visibility

32•vincko•6h ago•20 comments

Show HN: An open-source safety net for home hemodialysis

https://safehemo.com/
34•qweliantanner•3d ago•6 comments

Video Encoding and Decoding with Vulkan Compute Shaders in FFmpeg

https://www.khronos.org/blog/video-encoding-and-decoding-with-vulkan-compute-shaders-in-ffmpeg
144•y1n0•3d ago•53 comments

Flash-KMeans: Fast and Memory-Efficient Exact K-Means

https://arxiv.org/abs/2603.09229
160•matt_d•3d ago•14 comments

FSF statement on copyright infringement lawsuit Bartz v. Anthropic

https://www.fsf.org/blogs/licensing/2026-anthropic-settlement
253•m463•4d ago•125 comments

Monkey C – Small familiar language for apps on Garmin watches

https://developer.garmin.com/connect-iq/monkey-c/
7•embedding-shape•3h ago•0 comments