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•10mo ago

Comments

LegionMammal978•10mo 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•10mo 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•10mo 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.

Founder of GitLab battles cancer by founding companies

https://sytse.com/cancer/
883•bob_theslob646•13h ago•193 comments

OpenYak – An open-source Cowork that runs any model and owns your filesystem

https://github.com/openyak/desktop
55•wangzhangwu•2h ago•17 comments

CSS is DOOMed

https://nielsleenheer.com/articles/2026/css-is-doomed-rendering-doom-in-3d-with-css/
271•msephton•10h ago•64 comments

AI overly affirms users asking for personal advice

https://news.stanford.edu/stories/2026/03/ai-advice-sycophantic-models-research
595•oldfrenchfries•16h ago•449 comments

Alzheimer's disease mortality among taxi and ambulance drivers (2024)

https://www.bmj.com/content/387/bmj-2024-082194
93•bookofjoe•5h ago•48 comments

A Verilog to Factorio Compiler and Simulator (Working RISC-V CPU)

https://github.com/ben-j-c/verilog2factorio
50•signa11•2d ago•4 comments

The ANSI art "telecomics" of the 1992 election

https://breakintochat.com/blog/2026/03/25/don-lokke-and-mack-the-mouse/
18•Kirkman14•2d ago•1 comments

The case for becoming a manager

https://newsletter.thelongcommit.com/p/the-case-for-becoming-a-manager
23•jcmartinezdev•4d ago•16 comments

OpenBSD on Motorola 88000 Processors

http://miod.online.fr/software/openbsd/stories/m88k1.html
78•rbanffy•1d ago•8 comments

Further human + AI + proof assistant work on Knuth's "Claude Cycles" problem

https://twitter.com/BoWang87/status/2037648937453232504
186•mean_mistreater•12h ago•122 comments

I decompiled the White House's new app

https://thereallo.dev/blog/decompiling-the-white-house-app
471•amarcheschi•15h ago•180 comments

Cat Itecture: Better Cat Window Boxes

https://gwern.net/catitecture
45•gggscript•22h ago•4 comments

Sealing Paper Packaging Without Adhesives

https://www.fraunhofer.de/en/press/research-news/2026/march-2026/sealing-paper-packaging-without-...
60•gnabgib•7h ago•17 comments

The 667MHz Machine

https://www.0xsid.com/blog/667mhz-machine
37•ssiddharth•3d ago•5 comments

Linux is an interpreter

https://astrid.tech/2026/03/28/0/linux-is-an-interpreter/
186•frizlab•13h ago•41 comments

The first 40 months of the AI era

https://lzon.ca/posts/other/thoughts-ai-era/
158•jpmitchell•12h ago•85 comments

I Built an Open-World Engine for the N64 [video]

https://www.youtube.com/watch?v=lXxmIw9axWw
378•msephton•18h ago•65 comments

OpenCiv1 – open-source rewrite of Civ1

https://github.com/rajko-horvat/OpenCiv1
127•caminanteblanco•12h ago•35 comments

I turned my Kindle into my own personal newspaper

https://manualdousuario.net/en/how-to-kindle-personal-newspaper/
3•rpgbr•1d ago•0 comments

Meta Partners with Arm to Develop New Class of Data Center Silicon

https://about.fb.com/news/2026/03/meta-partners-with-arm-to-develop-new-class-of-data-center-sili...
56•eatonphil•4d ago•14 comments

South Korea Mandates Solar Panels for Public Parking Lots

https://www.reutersconnect.com/item/south-korea-mandates-solar-panels-for-public-parking-lots/dGF...
267•_____k•7h ago•146 comments

Spanish legislation as a Git repo

https://github.com/EnriqueLop/legalize-es
713•enriquelop•18h ago•217 comments

Google just gave Android power users a sideloading win

https://www.androidauthority.com/android-sideload-carry-over-3652845/
76•croemer•10h ago•91 comments

InpharmD (YC W21) Is Hiring – Senior Ruby on Rails Developer

https://inpharmd.com/jobs/senior-ruby-on-rails-engineer
1•tulasichintha•9h ago

1929: Inside the Greatest Crash in Wall Street History

https://www.nybooks.com/articles/2026/03/26/tick-tick-boom-1929-andrew-ross-sorkin/
64•mitchbob•4d ago•51 comments

The United States is driving a public health emergency of international concern

https://www.bmj.com/content/392/bmj-2026-089474
9•KnuthIsGod•1h ago•2 comments

Detecting file changes on macOS with kqueue

https://www.vegardstikbakke.com/kqueue/
74•benhoyt•4d ago•14 comments

Undroidwish – a single-file, batteries-included Tcl/Tk binary for many platforms

https://androwish.org/home/wiki?name=undroidwish
72•smartmic•13h ago•3 comments

Modeling what makes paper-folding puzzles hard

https://www.dailyunfold.com/blog/spatial-difficulty
14•astralasia•3d ago•12 comments

Improved Git Diffs with Delta, Fzf and a Little Shell Scripting

https://nickjanetakis.com/blog/awesome-git-diffs-with-delta-fzf-and-a-little-shell-scripting
143•nickjj•4d ago•36 comments