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.

Meta's blockbuster trial draws parallels to big tobacco

https://www.economist.com/business/2026/08/18/metas-blockbuster-trial-draws-parallels-to-big-tobacco
177•newsomix9xl•4h ago•129 comments

OpenLogi

https://openlogi.org/en
272•amatheus•4h ago•54 comments

Bun 1.4 Rust rewrite is not looking good

https://tipiirai.com/writing/bun-rust-rewrite-worries
57•tipiirai•36m ago•24 comments

Palomar: A registry of Lean verified mathematics

https://terrytao.wordpress.com/2026/08/18/palomar-a-registry-of-lean-verified-mathematics/
59•matt_d•3h ago•11 comments

Supersonic Trebuchet [video]

https://www.youtube.com/watch?v=Co57SfcT-h0
44•CharlesW•4d ago•3 comments

Scientists stunned by children's lung recovery in ultra low emission zone

https://www.bbc.com/news/articles/c1l1r1zne1ro
139•dabinat•5h ago•80 comments

A 3D fruit fly on macOS desktop powered by the real FlyWire connectome

https://github.com/DenisSergeevitch/desktop-fly
230•phoenix120•8h ago•76 comments

Cerebras CS-4

https://www.cerebras.ai/cs4
191•sunils34•5h ago•138 comments

The Vietnam Binh Chau (Chau Tan) Late Tang Wreck

https://www.koh-antique.com/client/tangwreck/tangwreck.html
21•teleforce•4h ago•0 comments

How does IKEA come up with names for its products?

https://www.ikea.com/se/en/customer-service/knowledge/articles/6f564c4d-2ccc-46de-b643-545a3948dc...
296•NaOH•12h ago•175 comments

CUDA Shared Memory Swizzling

https://leimao.github.io/blog/CUDA-Shared-Memory-Swizzling/
29•jxmorris12•5d ago•0 comments

AI usage patterns in software teams

https://linear.app/data
103•giuliomagnifico•8h ago•55 comments

Solo – a .so loader for static Linux binaries

https://github.com/pg83/solo
102•zX41ZdbW•6h ago•85 comments

Cursor launches Origin, GitHub alternative

https://cursor.com/changelog/origin-code-hosting
542•tomasreimers•1d ago•400 comments

Turbovec – Google's TurboQuant for vector search in Rust

https://github.com/RyanCodrai/turbovec
228•fittingopposite•12h ago•31 comments

Finger: the 1971 social network that never died

https://en.andros.dev/blog/54572bc7/finger-the-1971-social-network-that-never-died/
173•andros•23h ago•53 comments

And then the men with guns tell you to do it anyway

https://shkspr.mobi/blog/2026/08/and-then-the-men-with-guns-tell-you-to-do-it-anyway/
263•_djo_•13h ago•164 comments

Show HN: Automatically detect and patch walking-dead states in Sierra games

https://github.com/katiahayati/lucasartsifier/
27•wkfauna•4h ago•12 comments

Memory prices climb 500% in 12 months

https://www.tomshardware.com/pc-components/ram/memory-prices-climb-500-percent-in-12-months-up-to...
567•haunter•1d ago•474 comments

A 25-year-old video patent just expired, ending a legal headache for Linux

https://www.xda-developers.com/25-year-old-brazilian-video-patent-expired-legal-headache-linux/
149•theanonymousone•3d ago•50 comments

The Amazon tax

https://seths.blog/2026/08/the-amazon-tax/
1100•herbertl•17h ago•610 comments

Sticky wage norms and the real wage cost of unexpected inflation

https://bfi.uchicago.edu/wp-content/uploads/2026/08/BFI_WP_2026-108-1.pdf
344•jplusequalt•5h ago•190 comments

Claude writing a macOS driver for my obscure HP printer built only for Windows

https://twitter.com/kuberwastaken/status/2089377982536388964
169•porridgeraisin•18h ago•142 comments

Show HN: Interactive, animated architecture of any HuggingFace models

https://modelmap.cc
65•lizhaoliu•6h ago•7 comments

Universal health coverage could save $1T and 114k lives a year: study

https://ysph.yale.edu/news-article/universal-health-coverage-could-save-one-trillion-dollars-and-...
809•karakoram•1d ago•862 comments

Tiny satellite will use the dark side of the Moon as a shield

https://www.cam.ac.uk/research/news/tiny-satellite-will-use-the-dark-side-of-the-moon-to-eavesdro...
30•NordStreamYacht•5h ago•5 comments

Being ambitious and being a dad

https://nicholascharriere.com/blog/being-ambitious-and-being-a-dad/
398•nichochar•2d ago•241 comments

Apple announces changes for apps in the European Union

https://www.apple.com/newsroom/2026/08/apple-announces-changes-for-apps-in-the-european-union/
146•newusertoday•14h ago•201 comments

Beware Management Consultants

https://about.iceland.co.uk/our-story/the-dark-ages/beware-management-consultants/
506•KolmogorovComp•10h ago•126 comments

The 90-year history of the binoculars bolted to scenic overlooks

https://www.dpreview.com/news/the-90-year-history-of-the-binoculars-bolted-to-scenic-overlooks/
45•sohkamyung•7h ago•11 comments