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.

Emacs 31 Is Around the Corner: The Changes I'm Daily Driving

https://www.rahuljuliato.com/posts/emacs-31-around-the-corner
122•frou_dh•1h ago•35 comments

Has W Social switched to closed source?

https://blog.elenarossini.com/w-social-public-institutions-and-the-theater-of-european-digital-so...
61•nemoniac•1h ago•27 comments

Hospitals and universities repurposing drugs at 90% lower cost

https://www.kcl.ac.uk/news/hospitals-and-universities-repurposing-drugs-at-90-lower-cost
108•giuliomagnifico•3h ago•42 comments

I found 10k GitHub repositories distributing Trojan malware

https://orchidfiles.com/github-repositories-distributing-malware/
69•theorchid•2h ago•17 comments

Midjourney Medical

https://www.midjourney.com/medical/blogpost
1017•ricochet11•12h ago•706 comments

Advanced Compilers: The Self-Guided Online Course

https://www.cs.cornell.edu/courses/cs6120/2025fa/self-guided/
47•ibobev•3h ago•0 comments

DeepSeek Introduces Vision

https://chat.deepseek.com/
275•RIshabh235•7h ago•113 comments

Microsoft new Outlook takes 10 seconds to do what Outlook Classic does instantly

https://www.windowslatest.com/2026/06/15/microsofts-new-outlook-takes-10-seconds-to-do-what-outlo...
121•Adam-Hincu•1h ago•69 comments

Local Qwen isn't a worse Opus, it's a different tool

https://blog.alexellis.io/local-ai-is-not-opus/
325•alphabettsy•11h ago•170 comments

We built a persistent agent memory layer on Elasticsearch with 0.89 recall

https://www.elastic.co/search-labs/blog/agent-memory-elasticsearch
42•showmypost•2h ago•9 comments

Lore – Open source version control system designed for scalability

https://lore.org/
1188•regnerba•23h ago•631 comments

.gitignore Isn't the Only Way to Ignore Files in Git

https://nelson.cloud/.gitignore-isnt-the-only-way-to-ignore-files-in-git/
45•FergusArgyll•3h ago•2 comments

Modos Color Monitor Pushes E-Paper Displays Further

https://spectrum.ieee.org/modos-e-paper-monitor
21•Vinnl•2h ago•6 comments

Vinyl Cache and Varnish Cache

https://vinyl-cache.org/organization/on_vinyl_cache_and_varnish_cache.html#org-vinyl-varnish
37•embedding-shape•3d ago•12 comments

Seven Perfect Shuffles Randomize a Deck of Cards. But How Many Sloppy Ones?

https://www.quantamagazine.org/seven-perfect-shuffles-randomize-a-deck-of-cards-but-how-many-slop...
29•layer8•4h ago•20 comments

AMD silently removes memory encryption from consumer Ryzen CPUs

https://www.tomshardware.com/pc-components/cpus/amd-silently-removes-memory-encryption-from-consu...
263•lompad•5h ago•129 comments

US holds off blacklisting DeepSeek, more than 100 firms deemed security risks

https://www.reuters.com/world/china/us-holds-off-blacklisting-chinas-deepseek-more-than-100-firms...
491•giuliomagnifico•1d ago•539 comments

I need your clothes, your boots, and your motorcycle

https://rbelmont.mameworld.info/?p=1725
91•ingve•5h ago•80 comments

Wages in America Are Too Low for the 30% Rule to Work for Renters Anymore

https://www.realtor.com/advice/rent/wages-in-america-are-too-low-for-the-30-rule-to-work-for-rent...
98•littlexsparkee•45m ago•167 comments

I hate compilers

https://xeiaso.net/notes/2026/anubis-wasm-vendor-binary/
117•xena•8h ago•96 comments

Unity vs. Floating Point

https://aras-p.info/blog/2026/06/11/Unity-vs-floating-point/
8•ibobev•3d ago•0 comments

Sogen – High-performance Windows and Linux userspace emulator

https://sogen.dev/
54•fratellobigio•3d ago•16 comments

Clojure Hosted on Go

https://github.com/glojurelang/glojure
177•dnlo•14h ago•22 comments

How we run Firecracker VMs inside EC2 and start browsers in less than 1s

https://browser-use.com/posts/firecracker-browser-infra
300•gregpr07•1d ago•209 comments

Storied Colors – A catalogue of named colors

https://storiedcolors.com/
199•susiecambria•16h ago•47 comments

The Alaska Server

https://serialport.org/blog/the-alaska-server/
36•speckx•2d ago•10 comments

Taxonomy of the Occlupanida (parasitoids on bread bag tags)

https://www.horg.com/horg/?page_id=921
169•beatthatflight•14h ago•41 comments

Smashed Toilet Phone Web Server

https://www.offthebricks.com/articles/smashed-toilet-phone-web-server
34•mircerlancerous•3d ago•15 comments

RFC 10008: The new HTTP Query Method

https://www.rfc-editor.org/info/rfc10008/
392•schappim•1d ago•162 comments

How Madrid built its metro cheaply (2024)

https://worksinprogress.co/issue/how-madrid-built-its-metro-cheaply/
182•trymas•18h ago•131 comments