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.

The End of an Era

https://hughhowey.com/the-end-of-an-era/
40•harscoat•44m ago•15 comments

DeepSeek V4 Flash 0731 Intelligence, Performance and Price Analysis

https://artificialanalysis.ai/models/deepseek-v4-flash-ga
103•theanonymousone•4h ago•32 comments

The session you cannot take with you

https://earendil.com/posts/session-portability/
490•apitman•8h ago•128 comments

JEP 401: Value Objects (Preview) merged to OpenJDK master

https://github.com/openjdk/jdk/pull/31120
157•mfiguiere•7h ago•82 comments

DeepSeek-V4-Flash Update

https://api-docs.deepseek.com/updates/
383•dnhkng•6h ago•189 comments

IMAX vs. IMAX 70mm: The difference between these two cinema formats

https://www.engadget.com/2220571/differences-between-imax-70mm/
25•ksec•5d ago•19 comments

Tasklet (YC P26) Is Hiring a Customer Success Engineer

https://tasklet.ai/careers/customer-success-engineer
1•mayop100•35m ago

Google fixed more Chrome bugs in June than over the past two years, thanks to AI

https://blog.google/security/chrome-stronger-with-every-update/
163•Garbage•5h ago•182 comments

Stacked PRs are now live on GitHub

https://github.blog/changelog/2026-07-30-stacked-pull-requests-are-now-in-public-preview/
692•tomzorz•20h ago•240 comments

Gemini Robotics 2 brings whole body intelligence to robots

https://deepmind.google/blog/gemini-robotics-2-brings-whole-body-intelligence-to-robots/
578•ai2027•21h ago•464 comments

I flagged two research papers for fake authors and both were accepted as orals

https://geospatialml.com/posts/reviewing-ai-slop/
227•volumes94•14h ago•105 comments

How A Gang of Thieves Pulled Off a Multimillion-Dollar Data Center Heist

https://www.nytimes.com/2026/07/12/magazine/data-center-heist.html
12•chirau•5d ago•3 comments

Show HN: Gander, an Android file viewer that asks for no permissions at all

https://github.com/mokshablr/gander
101•mokshablr•6h ago•50 comments

The Religion of Speed

https://graybeard.ing/the-religion-of-speed/
197•MobiusHorizons•12h ago•90 comments

The mean means nothing: data visualization to debug a latency problem

https://fzakaria.com/2026/07/27/the-mean-means-nothing
60•fanf2•2d ago•12 comments

Read this before you buy that TV streaming stick

https://krebsonsecurity.com/2026/07/read-this-before-you-buy-that-tv-streaming-stick/
743•speckx•19h ago•446 comments

Where USB Memory Sticks are Born (2013)

https://www.bunniestudios.com/blog/2013/where-usb-memory-sticks-are-born/
67•jacquesm•3d ago•3 comments

Ruby Central's Destructive Legacy

https://andre.arko.net/2026/07/30/ruby-centrals-destructive-legacy/
5•4d66ba06•25m ago•2 comments

The Economic Benefit of Refactoring

https://martinfowler.com/articles/exploring-gen-ai/refactoring-economic-benefit.html
248•javaeeeee•21h ago•108 comments

Simulating TCP loss and congestion in browser using Go/WASM

https://ccsim.fly.dev
36•dilyevsky•2d ago•1 comments

GCC steering committee announces AI policy

https://lwn.net/Articles/1086041/
308•arto•1d ago•353 comments

Bad Apple but It's Traceroute

https://jssfr.de/2026-07-27-bad-apple-but-traceroute.html
132•jssfr•3d ago•43 comments

Memo-1: A 6502 computer built from scratch, using a Minitel as its terminal

https://github.com/MemoireMorte/Memo-1
87•sciences44•2d ago•12 comments

The lost civic life of movie rental stores

https://thereader.mitpress.mit.edu/the-lost-civic-life-of-movie-rental-stores/
186•facundo_olano•22h ago•242 comments

UEFA and its national associations will not participate in FIFA competitions

https://www.uefa.com/news-media/news/02a7-213a92896eb0-54dfbf454e3b-1000--statement-on-behalf-of-...
1101•dickfickling•17h ago•594 comments

CodePen 2.0

https://chriscoyier.net/2026/07/30/codepen-2-0/
173•robin_reala•18h ago•49 comments

Premier league bans gambling sponsors

https://www.footyheadlines.com/2646571793/betting-ban-takes-effect-no-more-gambling-sponsors-in-t...
53•paoliniluis•12h ago•9 comments

The AI Aesthetic

https://blog.jim-nielsen.com/2026/ai-aesthetic/
329•montroser•13h ago•148 comments

Rune 1.1: adds Python, an Emacs editor, a symbol index and is now free

https://rune.build/blog/rune-1-1-release
89•ernestrc•14h ago•39 comments

Show HN: Distilling DeepSeek into GPT-OSS doesn't transfer censorship. Try it

https://www.ctgt.ai/research/distillation-censorship-transfer
137•cgorlla•18h ago•68 comments