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.

Pokémon Go Scans Trained the Navigation Tech for Military Drones

https://dronexl.co/2026/06/09/pokemon-go-scans-niantic-vantor-military-drone-navigation/
72•vrganj•57m ago•21 comments

AI agent runs amok in Fedora and elsewhere

https://lwn.net/SubscriberLink/1077035/c7e7c14fbd60fae9/
355•tanelpoder•7h ago•119 comments

Cybersecurity researchers aren't happy about the guardrails on Anthropic's Fable

https://techcrunch.com/2026/06/10/cybersecurity-researchers-arent-happy-about-the-guardrails-on-a...
390•speckx•14h ago•349 comments

πFS

https://github.com/philipl/pifs
705•helterskelter•12h ago•161 comments

Macaroni – a single HTML file messenger

https://github.com/vanyapr/makaroshki
15•snowflaxxx•1h ago•5 comments

Anthropic requires 30 day data retention for Fable and Mythos

https://support.claude.com/en/articles/15425996-data-retention-practices-for-mythos-class-models
377•lebovic•1d ago•171 comments

Reverse engineering the Creative Katana soundbar to control it from Linux

https://blog.nns.ee/2026/02/20/katana-v2x-re/
40•theanonymousone•3d ago•2 comments

Sequoyah’s syllabary created a written language for the Cherokee

https://www.smithsonianmag.com/innovation/man-created-written-language-cherokee-did-efficiently-e...
146•grahambargeron•9h ago•91 comments

Starfish by Peter Watts (1999)

https://www.rifters.com/real/STARFISH.htm#prelude
21•zetalyrae•2d ago•5 comments

I'm Eric Ries, author of "The Lean Startup" and new book "Incorruptible" – AMA

634•eries•16h ago•475 comments

Vacuum-Form Signage

https://bethmathews.substack.com/p/the-history-behind-the-signs-lighting
58•benbreen•1d ago•11 comments

The Road to the WASM Component Model 1.0

https://bytecodealliance.org/articles/the-road-to-component-model-1-0
68•emschwartz•2d ago•43 comments

Klondike Solitaire game for curses in 5k of C

https://nanochess.org/klondike_in_c.html
68•nanochess•2d ago•6 comments

PgDog is funded and coming to a database near you

https://pgdog.dev/blog/our-funding-announcement
438•levkk•17h ago•218 comments

How JPL keeps the 13-year-old Curiosity rover doing science

https://spectrum.ieee.org/curiosity-rover-jpl-mars-science
217•pseudolus•14h ago•58 comments

GeoLibre 1.0

https://geolibre.app/
218•jonbaer•14h ago•18 comments

L'Affaire Siloxane

https://mceglowski.substack.com/p/laffaire-siloxane
208•idlewords•2d ago•33 comments

CSS: Unavoidable Bad Parts

https://matklad.github.io/2026/06/04/css-unavoidable-bad-parts.html
62•surprisetalk•1d ago•16 comments

Show HN: Extend UI – open-source UI kit for modern document apps

https://www.extend.ai/ui
201•kbyatnal•15h ago•47 comments

What is it like to be a bat? (1974) [pdf]

https://www.sas.upenn.edu/~cavitch/pdf-library/Nagel_Bat.pdf
83•shadow28•11h ago•89 comments

Are insecure code completions in PyCharm a vulnerability?

https://sethmlarson.dev/are-insecure-code-completions-a-vulnerability
28•12_throw_away•6h ago•12 comments

World Capitals Voronoi

https://www.jasondavies.com/maps/voronoi/capitals/
75•vincnetas•2d ago•35 comments

Who's the smartest corvid?

https://thetyee.ca/Culture/2026/06/05/Whos-the-Smartest-Corvid/
97•NaOH•1d ago•85 comments

The Conductor Rewrite: What They Changed to Make It Fast

https://performance.dev/the-conductor-rewrite
5•Charlieholtz•1d ago•2 comments

Raspberry Pi 5 – 16GB RAM

https://www.adafruit.com/product/6125?src=raspberrypi
241•akman•11h ago•245 comments

Building an HTML-first site doubled our users overnight

https://mohkohn.co.uk/writing/html-first/
1091•edent•18h ago•494 comments

Show HN: HelixDB – A graph database built on object storage

https://github.com/HelixDB/helix-db/tree/main
116•GeorgeCurtis•15h ago•34 comments

Apache Burr: Build reliable AI agents and applications

https://burr.apache.org/
205•anhldbk•16h ago•99 comments

Validation, Docs, tests, and database schemas from one source of truth

https://github.com/justhamade/triadjs
4•justhamade•2h ago•1 comments

Deficient executive control in transformer attention

https://academic.oup.com/pnasnexus/article/5/6/pgag149/8698838
32•derbOac•8h ago•11 comments