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•6mo ago

Comments

LegionMammal978•6mo 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•6mo 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•6mo 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.

How Quake.exe got its TCP/IP stack

https://fabiensanglard.net/quake_chunnel/index.html
165•billiob•3h ago•15 comments

Cloudflare Global Network experiencing issues

https://www.cloudflarestatus.com/incidents/8gmgl950y3h7
105•meetpateltech•18m ago•37 comments

The Uselessness of "Fast" and "Slow" in Programming

https://jerf.org/iri/post/2025/the_uselessness_of_fast/
22•zdw•6d ago•4 comments

How many video games include a marriage proposal? At least one

https://32bits.substack.com/p/under-the-microscope-ncaa-basketball
242•bbayles•4d ago•54 comments

Show HN: I built a synth for my daughter

https://bitsnpieces.dev/posts/a-synth-for-my-daughter/
1157•random_moonwalk•5d ago•198 comments

Cloudflare, X, More are down

https://www.cloudflarestatus.com/?t=1
364•imdsm•32m ago•203 comments

Ruby Symbols

https://tech.stonecharioteer.com/posts/2025/ruby-symbols/
21•stonecharioteer•5d ago•12 comments

Unofficial "Tier 4" Rust Target for older Windows versions

https://github.com/rust9x/rust
97•kristianp•9h ago•50 comments

Azure hit by 15 Tbps DDoS attack using 500k IP addresses

https://www.bleepingcomputer.com/news/microsoft/microsoft-aisuru-botnet-used-500-000-ips-in-15-tb...
368•speckx•18h ago•250 comments

When Reverse Proxies Surprise You: Hard Lessons from Operating at Scale

https://www.infoq.com/articles/scaling-reverse-proxies/
42•miggy•4d ago•3 comments

Compiling Ruby to machine language

https://patshaughnessy.net/2025/11/17/compiling-ruby-to-machine-language
257•todsacerdoti•16h ago•45 comments

The Miracle of Wörgl

https://scf.green/story-of-worgl-and-others/
4•simonebrunozzi•1h ago•0 comments

Rebecca Heineman has died

https://www.pcgamer.com/gaming-industry/legendary-game-designer-programmer-space-invaders-champio...
566•shdon•10h ago•84 comments

My stages of learning to be a socially normal person

https://sashachapin.substack.com/p/my-six-stages-of-learning-to-be-a
492•eatitraw•2d ago•323 comments

Comparing Android Alternatives: Lineage OS, ∕E∕OS, and Graphene OS

https://kevinboone.me/lineage-eos-graphene.html
14•ingve•2h ago•0 comments

Langfuse (YC W23) Hiring OSS Support Engineers in Berlin and SF

https://jobs.ashbyhq.com/langfuse/5ff18d4d-9066-4c67-8ecc-ffc0e295fee6
1•clemo_ra•5h ago

Astrophotographer snaps skydiver falling in front of the sun

https://www.iflscience.com/the-fall-of-icarus-you-have-never-seen-an-astrophotography-picture-lik...
396•doener•2d ago•78 comments

Project Gemini

https://geminiprotocol.net/
291•andsoitis•20h ago•165 comments

FreeMDU: Open-source Miele appliance diagnostic tools

https://github.com/medusalix/FreeMDU
307•Medusalix•22h ago•82 comments

The surprising benefits of giving up

https://nautil.us/the-surprising-benefits-of-giving-up-1248362/
100•jnord•7h ago•81 comments

Show HN: Parqeye – A CLI tool to visualize and inspect Parquet files

https://github.com/kaushiksrini/parqeye
116•kaushiksrini•12h ago•30 comments

Windows 11 adds AI agent that runs in background with access to personal folders

https://www.windowslatest.com/2025/11/18/windows-11-to-add-an-ai-agent-that-runs-in-background-wi...
474•jinxmeta•12h ago•408 comments

Ditch your (mut)ex, you deserve better

https://chrispenner.ca/posts/mutexes
81•commandersaki•6d ago•69 comments

Run ancient UNIX on modern hardware

https://github.com/felipenlunkes/run-ancient-unix
103•doener•14h ago•23 comments

LeJEPA

https://arxiv.org/abs/2511.08544
48•nothrowaways•9h ago•12 comments

Raccoons are showing early signs of domestication

https://www.scientificamerican.com/article/raccoons-are-showing-early-signs-of-domestication/
162•pavel_lishin•3d ago•127 comments

How when AWS was down, we were not

https://authress.io/knowledge-base/articles/2025/11/01/how-we-prevent-aws-downtime-impacts
170•mooreds•19h ago•62 comments

WeatherNext 2: Our most advanced weather forecasting model

https://blog.google/technology/google-deepmind/weathernext-2/
263•meetpateltech•21h ago•118 comments

Show HN: ESPectre – Motion detection based on Wi-Fi spectre analysis

https://github.com/francescopace/espectre
179•francescopace•21h ago•45 comments

Aldous Huxley predicts Adderall and champions alternative therapies

https://angadh.com/inkhaven-7
107•surprisetalk•21h ago•125 comments