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.

South Korea Mandates Solar Panels for Public Parking Lots

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

Founder of GitLab battles cancer by founding companies

https://sytse.com/cancer/
653•bob_theslob646•6h ago•160 comments

CSS is DOOMed

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

OpenBSD on Motorola 88000 Processors

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

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

https://twitter.com/BoWang87/status/2037648937453232504
132•mean_mistreater•5h ago•94 comments

AI overly affirms users asking for personal advice

https://news.stanford.edu/stories/2026/03/ai-advice-sycophantic-models-research
505•oldfrenchfries•10h ago•397 comments

The first 40 months of the AI era

https://lzon.ca/posts/other/thoughts-ai-era/
93•jpmitchell•5h ago•34 comments

Linux is an interpreter

https://astrid.tech/2026/03/28/0/linux-is-an-interpreter/
154•frizlab•7h ago•29 comments

OpenCiv1 – open-source rewrite of Civ1

https://github.com/rajko-horvat/OpenCiv1
76•caminanteblanco•6h ago•25 comments

I decompiled the White House's new app

https://thereallo.dev/blog/decompiling-the-white-house-app
348•amarcheschi•8h ago•124 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...
27•eatonphil•4d ago•4 comments

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

https://inpharmd.com/jobs/senior-ruby-on-rails-engineer
1•tulasichintha•2h 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/
39•mitchbob•3d ago•38 comments

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

https://www.youtube.com/watch?v=lXxmIw9axWw
339•msephton•12h ago•57 comments

Cocoa-Way – Native macOS Wayland compositor for running Linux apps seamlessly

https://github.com/J-x-Z/cocoa-way
297•OJFord•14h ago•93 comments

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

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

Detecting file changes on macOS with kqueue

https://www.vegardstikbakke.com/kqueue/
62•benhoyt•4d ago•8 comments

Spanish legislation as a Git repo

https://github.com/EnriqueLop/legalize-es
689•enriquelop•12h ago•212 comments

Stop picking my Go version for me

https://blog.howardjohn.info/posts/go-mod-version/
7•ingve•2h ago•0 comments

Computer chip material inspired by the human brain could slash AI energy use

https://www.cam.ac.uk/research/news/new-computer-chip-material-inspired-by-the-human-brain-could-...
6•hhs•1h ago•1 comments

TreeTrek – A raw Git repository viewer web app

https://repo.autonoma.ca/treetrek
4•maxloh•1h ago•2 comments

My heuristics are wrong. What now?

https://brooker.co.za/blog/2026/03/20/ic-leadership.html
29•herbertl•4d ago•3 comments

rpg.actor Game Jam

https://rpg.actor/jam
62•Kye•8h ago•5 comments

Circuit-level PDP-11/34 emulator

https://github.com/dbrll/ll-34
45•elvis70•8h ago•5 comments

Private equity turned vulnerable elderly people into human ATMs

https://www.theguardian.com/society/2026/mar/28/the-great-care-home-cash-grab-how-private-equity-...
65•mordechai9000•2h ago•33 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
116•nickjj•4d ago•34 comments

Goldman Sachs now reckons that oil could take out the 2008 record of $147

https://www.ft.com/content/360ca227-4d2a-41a4-a05f-41baedc0f7d2
38•bookofjoe•2h ago•14 comments

ICAO issued new power bank restriction on flight

https://www.icao.int/news/new-power-bank-restrictions-will-safeguard-international-aviation
55•phantomathkg•10h ago•80 comments

C++26: A User-Friednly assert() macro

https://www.sandordargo.com/blog/2026/03/25/cpp26-user-friendly-assert
59•jandeboevrie•3d ago•46 comments

Sealing Paper Packaging Without Adhesives

https://www.fraunhofer.de/en/press/research-news/2026/march-2026/sealing-paper-packaging-without-...
4•gnabgib•1h ago•0 comments