frontpage.
newsnewestaskshowjobs

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.

Free alternative TV network built from the Internet Archive's forgotten videos

https://spelunkr.tv
255•SockThief•3h ago•41 comments

A Beginner's Guide to Local AI with Inkling, Qwen, and Unsloth

https://www.gpupartner.com/blog/beginners-guide-local-ai-inkling-qwen-unsloth
347•Retell15•7h ago•143 comments

XNU Linux: Full OS X GUI Userspace on Linux

https://github.com/AFK-surf/xnulinux
25•mmastrac•1h ago•7 comments

Masullo on the Riemann Hypothesis

https://johncarlosbaez.wordpress.com/2026/11/22/masullo-on-the-riemann-hypothesis/
113•xiaoyu2006•17h ago•45 comments

The Birds of GTA 6: A Field Guide to Vice City and Leonida's Wildlife

https://www.audubon.org/magazine/birds-of-gta-6-field-guide-vice-city-wildlife
410•gaws•9h ago•204 comments

Cathedral floor emerges in Sudan, revealing one of the biggest medieval churches

https://apnews.com/article/sudan-antiquities-nubia-cathedral-1b16f67da881ee5592de4481ee55c527
158•graemep•4d ago•24 comments

The New Docker: Built to Run on Trust

https://www.docker.com/blog/meet-the-new-docker-built-to-run-on-trust/
10•peer2pay•1h ago•8 comments

A miniature San Francisco with live buses, planes and boats

https://smallsf.com/
196•dutilh•8h ago•81 comments

GL.iNet Security Notice 2026-11-20

https://www.gl-inet.com/en-us/blogs/blog/glinet-security-notice-2026-11-20
135•gregsadetsky•5h ago•65 comments

LittleBit: Ultra Low-Bit Quantization via Latent Factorization

https://arxiv.org/abs/2506.13771
11•kakadu•3d ago•1 comments

The Usefulness of Useless Knowledge [pdf] (1939)

https://www.ias.edu/sites/default/files/library/UsefulnessHarpers.pdf
91•hectormauer•6h ago•15 comments

The struggle for freedom: How BSD escaped AT&T licensing

https://fosscomics.com/posts/16.%20BSD%20Unix%20Part%206%20-%20The%20Struggle%20for%20Freedom/
81•joonehur•7h ago•28 comments

The Unlicensed Gospel: Wisdom Tree's Bible Games on the Game Boy

https://www.gameboymuseum.com/single-post/the-unlicensed-gospel-wisdom-tree-s-bible-games-on-the-...
29•speckx•3d ago•9 comments

Assume People Are Not Interested in Your Blog Post

https://danielsada.tech/blog/assume-people-are-not-interested-in-your-blog-post/
108•dshacker•9h ago•56 comments

What we learned operating auth for 1k APIs

https://nango.dev/blog/lessons-from-operating-api-auth-for-900-apis/
20•fagnerbrack•3h ago•3 comments

Perplexity and Intelligence

https://openai.com/index/perplexity-and-intelligence/
526•acossta•11h ago•361 comments

Nyx, the Oldest Internet Service Provider

https://nyx.net/
116•o_-_o•8h ago•14 comments

Progress map for the Lean formalization of Alessandro Masullo's manuscript

https://claude.ai/artifact/CtQyX8qfYAF822bgHJHHE3
187•Qision•5h ago•152 comments

Verifying formal models of Raft implementations

https://antithesis.com/blog/2026/verifying-formal-models/
10•alpaylan•2d ago•0 comments

Show HN: I built a game where you are an LLM's subagent

https://github.com/gulivan/worker755
291•ivantgam•14h ago•69 comments

What Happened to Silicon Valley?

https://www.oreilly.com/radar/what-happened-to-silicon-valley/
521•greenyouse•9h ago•290 comments

0rwx – A simple model of AI usage, inspired by Unix permissions

https://0rwx.com/
33•misswaterfairy•4h ago•6 comments

How the World Draws the World

https://googlemapsmania.blogspot.com/2026/10/how-world-draws-world.html
18•surprisetalk•2d ago•1 comments

Advice for Young Researchers

http://togelius.blogspot.com/2026/11/advice-for-young-researchers.html
69•tcumulus•4d ago•26 comments

Treemap of the Riemann Hypothesis Lean Proof

https://pengowray.github.io/riemann-zeta-proof-visualizer/
9•pengowray•3h ago•1 comments

Advanced Character Physics (2001) [pdf]

https://www.cs.cmu.edu/afs/cs/academic/class/15462-s13/www/lec_slides/Jakobsen.pdf
9•tomatofu•2h ago•0 comments

Localcode, open source agentic coding on your Mac with one command

https://github.com/mjwsolo/localcode
41•mjwsolo•6h ago•13 comments

I joined the NTP Pool, but not with my Stratum 1 Pi

https://www.jeffgeerling.com/blog/2026/i-joined-the-ntp-pool/
138•fortran77•13h ago•46 comments

Toyota, Nissan, and Honda to standardize parts to lower costs

https://www.caranddriver.com/news/a74490092/toyota-nissan-honda-standardize-parts-lower-costs/
1228•zdw•1d ago•686 comments

Open Social Web Alliance

https://osw-alliance.net/en/
233•doener•13h ago•223 comments