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.

Pebble Watch software is now open source

https://ericmigi.com/blog/pebble-watch-software-is-now-100percent-open-source
1040•Larrikin•18h ago•193 comments

Most Stable Raspberry Pi? 81% Better NTP with Thermal Management

https://austinsnerdythings.com/2025/11/24/worlds-most-stable-raspberry-pi-81-better-ntp-with-ther...
158•todsacerdoti•6h ago•48 comments

Human brains are preconfigured with instructions for understanding the world

https://news.ucsc.edu/2025/11/sharf-preconfigured-brain/
168•XzetaU8•6h ago•106 comments

Unpowered SSDs slowly lose data

https://www.xda-developers.com/your-unpowered-ssd-is-slowly-losing-your-data/
523•amichail•17h ago•224 comments

Meta Segment Anything Model 3

https://ai.meta.com/blog/segment-anything-model-3/?_fb_noscript=1
19•alcinos•5d ago•1 comments

Claude Advanced Tool Use

https://www.anthropic.com/engineering/advanced-tool-use
533•lebovic•17h ago•219 comments

Broccoli Man, Remastered

https://mbleigh.dev/posts/broccoli-man-remastered/
20•mbleigh•5d ago•3 comments

Using an Array of Needles to Create Solid Knitted Shapes

https://dl.acm.org/doi/10.1145/3746059.3747759
24•PaulHoule•3d ago•3 comments

Show HN: I built an interactive HN Simulator

https://news.ysimulator.run/news
374•johnsillings•19h ago•173 comments

How the Atomic Tests Looked Like from Los Angeles

https://www.amusingplanet.com/2016/09/how-atomic-tests-looked-like-from-los.html
64•ohjeez•3d ago•36 comments

Cool-retro-term: terminal emulator which mimics look and feel of CRTs

https://github.com/Swordfish90/cool-retro-term
248•michalpleban•19h ago•91 comments

Implications of AI to schools

https://twitter.com/karpathy/status/1993010584175141038
247•bilsbie•19h ago•270 comments

Dumb Ways to Die: Printed Ephemera

https://ilovetypography.com/2025/11/19/dumb-ways-to-die-printed-ephemera/
20•jjgreen•5d ago•12 comments

Build a Compiler in Five Projects

https://kmicinski.com/functional-programming/2025/11/23/build-a-language/
132•azhenley•1d ago•23 comments

What OpenAI did when ChatGPT users lost touch with reality

https://www.nytimes.com/2025/11/23/technology/openai-chatgpt-users-risks.html
213•nonprofiteer•1d ago•319 comments

Show HN: OCR Arena – A playground for OCR models

https://www.ocrarena.ai/battle
159•kbyatnal•3d ago•51 comments

Rethinking C++: Architecture, Concepts, and Responsibility

https://blogs.embarcadero.com/rethinking-c-architecture-concepts-and-responsibility/
31•timeoperator•5d ago•18 comments

Claude Opus 4.5

https://www.anthropic.com/news/claude-opus-4-5
983•adocomplete•18h ago•448 comments

How did the Win 95 user interface code get brought to the Windows NT code base?

https://devblogs.microsoft.com/oldnewthing/20251028-00/?p=111733
108•ayi•3d ago•61 comments

Chrome Jpegxl Issue Reopened

https://issues.chromium.org/issues/40168998
259•markdog12•1d ago•118 comments

Google's new 'Aluminium OS' project brings Android to PC

https://www.androidauthority.com/aluminium-os-android-for-pcs-3619092/
136•jmsflknr•18h ago•187 comments

Shai-Hulud Returns: Over 300 NPM Packages Infected

https://helixguard.ai/blog/malicious-sha1hulud-2025-11-24
960•mrdosija•1d ago•728 comments

The Bitter Lesson of LLM Extensions

https://www.sawyerhood.com/blog/llm-extension
123•sawyerjhood•18h ago•63 comments

Fifty Shades of OOP

https://lesleylai.info/en/fifty_shades_of_oop/
117•todsacerdoti•1d ago•65 comments

Building the largest known Kubernetes cluster

https://cloud.google.com/blog/products/containers-kubernetes/how-we-built-a-130000-node-gke-cluster/
136•TangerineDream•3d ago•77 comments

Three Years from GPT-3 to Gemini 3

https://www.oneusefulthing.org/p/three-years-from-gpt-3-to-gemini
294•JumpCrisscross•2d ago•217 comments

AI has a deep understanding of how this code works

https://github.com/ocaml/ocaml/pull/14369
142•theresistor•15h ago•48 comments

Inside Rust's std and parking_lot mutexes – who wins?

https://blog.cuongle.dev/p/inside-rusts-std-and-parking-lot-mutexes-who-win
180•signa11•5d ago•81 comments

PS5 now costs less than 64GB of DDR5 memory. RAM jumps to $600 due to shortage

https://www.tomshardware.com/pc-components/ddr5/64gb-of-ddr5-memory-now-costs-more-than-an-entire...
417•speckx•17h ago•282 comments

Using Antigravity for Statistical Physics in JavaScript

https://christopherkrapu.com/blog/2025/antigravity-stat-mech/
27•ckrapu•3d ago•22 comments