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.

Google adds 24-hour wait and mandatory reboot to Android sideloading flow

https://android-developers.googleblog.com/2025/08/elevating-android-security.html
23•dfordp11•56m ago•10 comments

OpenCode – Open source AI coding agent

https://opencode.ai/
656•rbanffy•9h ago•287 comments

Ubuntu 26.04 Ends 46 Years of Silent sudo Passwords

https://pbxscience.com/ubuntu-26-04-ends-46-years-of-silent-sudo-passwords/
19•akersten•1h ago•7 comments

Mamba-3

https://www.together.ai/blog/mamba-3
55•matt_d•3d ago•4 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-...
539•MrDresden•17h ago•428 comments

Molly Guard

https://bookofjoe2.blogspot.com/2026/02/molly-guard.html
60•surprisetalk•16h ago•28 comments

Fujifilm X RAW STUDIO webapp clone

https://github.com/eggricesoy/filmkit
10•notcodingtoday•2d ago•6 comments

We rewrote our Rust WASM parser in TypeScript and it got faster

https://www.openui.com/blog/rust-wasm-parser
166•zahlekhan•9h ago•92 comments

A Japanese glossary of chopsticks faux pas

https://www.nippon.com/en/japan-data/h01362/
212•cainxinth•10h ago•154 comments

Ghostling

https://github.com/ghostty-org/ghostling
169•bjornroberg•8h ago•29 comments

FFmpeg 101 (2024)

https://blogs.igalia.com/llepage/ffmpeg-101/
26•vinhnx•4h ago•0 comments

Linux Applications Programming by Example: The Fundamental APIs (2nd Edition)

https://github.com/arnoldrobbins/LinuxByExample-2e
67•teleforce•7h ago•8 comments

The Ugliest Airplane: An Appreciation

https://www.smithsonianmag.com/air-space-magazine/ugliest-airplane-appreciation-180978708/
51•randycupertino•2d ago•28 comments

A look at content scrambling in DVDs

https://mathweb.ucsd.edu/~crypto/Projects/MarkBarry/
23•rvnx•2d ago•10 comments

Attention Residuals

https://github.com/MoonshotAI/Attention-Residuals
153•GaggiX•12h ago•21 comments

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

https://github.com/FormerLab/fortransky
69•FormerLabFred•8h ago•35 comments

The Los Angeles Aqueduct Is Wild

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

Turing Award Honors Bennett and Brassard for Quantum Information Science

https://amturing.acm.org
18•throw0101d•2d ago•0 comments

The worst volume control UI in the world (2017)

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

VisiCalc Reconstructed

https://zserge.com/posts/visicalc/
182•ingve•3d ago•74 comments

Ask ChatGPT to pick a number from 1-10000, it generally selects from 7200-7500

https://old.reddit.com/r/ChatGPT/comments/1rz2ooh/i_am_betting_my_house_that_if_you_ask_gpt_to_pick/
10•mellosouls•46m ago•7 comments

Lent and Lisp

https://leancrew.com/all-this/2026/02/lent-and-lisp/
43•surprisetalk•2d ago•2 comments

purl: a curl-esque CLI for making HTTP requests that require payment

https://www.purl.dev/
17•bpierre•4h ago•2 comments

Our commitment to Windows quality

https://blogs.windows.com/windows-insider/2026/03/20/our-commitment-to-windows-quality/
488•hadrien01•11h ago•882 comments

An FAQ on Reinforcement Learning Environments

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

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

https://github.com/RedGridTactical/RedGridLink
37•redgridtactical•8h ago•14 comments

Entso-E final report on Iberian 2025 blackout

https://www.entsoe.eu/publications/blackout/28-april-2025-iberian-blackout/
181•Rygian•19h ago•89 comments

Delve – Fake Compliance as a Service

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

ArXiv declares independence from Cornell

https://www.science.org/content/article/arxiv-pioneering-preprint-server-declares-independence-co...
746•bookstore-romeo•1d ago•263 comments

Parallel Perl – Autoparallelizing interpreter with JIT

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