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.

Playa Phone

https://playaphone.com/
198•cutoff•2h ago•83 comments

I turned my security cameras into an automatic bird identification system

https://jasontucker.blog/how-i-turned-my-security-cameras-into-an-automatic-bird-identification-s...
23•speckx•29m ago•9 comments

ravynOS: Pre-alpha open-source OS based on Darwin, FreeBSD, Apple open-source

https://ravynos.com/
30•Bluestein•57m ago•16 comments

ChatGPT Work Tool and Skill Reference

https://codex-tool-reference.simonw.chatgpt.site/
101•ijidak•3h ago•44 comments

Launch HN: Almanac (YC S26) – AI that knows your company

https://usealmanac.com/
17•kushagrchitkar•1h ago•13 comments

C++26: Standard Library Hardening Experiments

https://www.cppstories.com/2026/hardening-experiments/
41•ibobev•2h ago•24 comments

Launch HN: Hebbian Robotics (YC S26) – Build scalable robotics data pipelines

https://github.com/Hebbian-Robotics/hflow
21•kstonekuan•2h ago•4 comments

The Snow/Leavis ‘two cultures’ clash

https://aeon.co/essays/at-the-heart-of-the-snow-leavis-two-cultures-clash
37•Hooke•2h ago•18 comments

OpenShot 4.0 – Open-source video editor

https://www.openshot.org/blog/2026/08/30/openshot-40-record-edit-color-like-never-before/
418•metrofun•7h ago•98 comments

Navigation App for People with Blindness and Low Vision

https://seas.harvard.edu/news/smartphone-navigation-app-people-blindness-and-low-vision
19•geox•4d ago•7 comments

DNS Abuse and Criminal Infrastructure

https://labs.ripe.net/author/andrew_campling/dns-abuse-and-criminal-infrastructure-beyond-definit...
40•jruohonen•1d ago•23 comments

Breaking Claude Code Opus 5 Auto Mode

https://embracethered.com/blog/posts/2026/breaking-claude-code-opus-5-and-automode/
287•Recursing•9h ago•94 comments

Konrad Zuse Museum shutting down due to lack of funding

https://www.heise.de/en/news/Zuse-Computer-Museum-ZCOM-in-Hoyerswerda-faces-closure-11344513.html
25•virtualritz•24m ago•6 comments

Agentic Trust Controls

https://trustcontrols.ai/
18•mooreds•2h ago•3 comments

Agent Memory as a File Format

https://calpaterson.com/memoryfields.html
121•ingve•5h ago•58 comments

Agents still can't automate Excel

https://www.orcaset.com/blog/agents-still-can-t-automate-excel
15•jrdnh•4d ago•8 comments

Malleable software = solid bases and custom code

https://www.mdubakov.me/malleable-software-solid-bases-custom-code/
72•tablet•6h ago•25 comments

uv: Deduplicate all files in the wheel cache

https://github.com/astral-sh/uv/pull/21327
173•tosh•11h ago•83 comments

The Art of Chip-8

http://beyondloom.com/blog/artofchip8.html
39•surprisetalk•1w ago•7 comments

My hobby of building miniatures and taking pretty pictures

https://sandyuraz.com/blogs/tiny-cafe/
321•thecsw•3d ago•56 comments

Marx, Keynes, and AI

https://www.unpopularfront.news/p/marx-keynes-and-ai
42•speckx•2h ago•32 comments

Study: Blue light impairs the eye's ability to distinguish fine detail most

https://research.uga.edu/news/blue-light-has-a-surprising-effect-on-your-eyes-study-finds/
75•giuliomagnifico•8h ago•41 comments

Doubling of Kobo's U.S. sales in both 2025 and 2026, 70% US female customer base

https://www.reddit.com/r/kobo/comments/1w20azv/the_doubling_of_kobos_us_sales_in_both_2025_and/
67•seam_carver•2h ago•54 comments

Apache Iggy, a message streaming platform in Rust, graduates to an Apache TLP

https://iggy.apache.org/blogs/2026/08/24/apache-iggy-top-level-project-tlp-graduation/
71•spetz•2h ago•15 comments

“I just chose words carefully”

https://unsung.aresluna.org/i-just-chose-words-carefully/
1123•zdw•18h ago•318 comments

Mental Health Workers Say Algorithmic Triage Is Hurting Patients

https://capitalandmain.com/mental-health-workers-say-algorithmic-triage-is-hurting-patients
42•hn_acker•37m ago•8 comments

State of the Map 2026: OpenStreetMap conference

https://povesham.wordpress.com/2026/08/30/state-of-the-map-2026-openstreetmap-conference/
53•altilunium•8h ago•4 comments

British Museum hosted Peter Thiel in private viewing of Bayeux tapestry

https://www.theguardian.com/culture/2026/aug/31/british-museum-hosted-palantir-founder-peter-thie...
7•tomwphillips•23m ago•0 comments

P99 0 ms* autocomplete for 240M domain names

https://ruurtjan.com/articles/p99-0ms-autocomplete-for-240-million-domain-names
203•dbalatero•13h ago•75 comments

Transfer files over an Ethernet patch cable

https://maurycyz.com/misc/etherfiles/
133•jllyhill•13h ago•140 comments