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.

Denmark Requires Oral Defenses for Students' Written Work to Counter AI Cheating

https://mezha.net/eng/bukvy/ca117584_denmark_requires_oral/
389•theanonymousone•3h ago•184 comments

"Code was never the hard part" is an insult to all programmers

https://blog.senko.net/code-was-never-the-hard-part-is-an-insult-to-all-programmers
439•senko•7h ago•280 comments

Fastmail offers EU data region

https://www.fastmail.com/blog/fastmail-offers-eu-data-region/
269•groomlake•6h ago•120 comments

Maryland Closes More of Cunningham Falls State Park After Second Beaver Attack

https://news.maryland.gov/dnr/2026/08/05/dnr-closes-additional-areas-of-cunningham-falls-state-pa...
28•bookofjoe•1h ago•10 comments

LinkedIn Feed Blocker

https://github.com/andrewpollack/linkedin-feed-blocker
145•andrewpollack•5h ago•81 comments

A domain can now say it is for sale, in DNS

https://specification.website/spec/foundations/for-sale-dns/
300•shaunpud•8h ago•123 comments

Open-source interactive map for the Aug 12 total solar eclipse

https://eclipsefan.org/?v=2&t=max&layers=eclipse%2Cbesselian%2Cumbra-live%2Cshadow-3d%2Ccloud-pro...
42•MarcoDewey•2h ago•6 comments

Can Intel finally beat ARM on performance per Watt?

https://hackaday.com/2026/08/08/want-energy-efficiency-dude-youre-getting-a-dell/
119•gumby•6h ago•42 comments

DeepMind's WeatherNext model achieves breakthrough forecasting cyclones

https://deepmind.google/blog/weathernext-ai-model-achieves-breakthrough-in-forecasting-cyclones/
345•bhavansig•12h ago•106 comments

Timeline of the OpenAI accidental attack against Hugging Face

https://simonwillison.net/2026/Aug/7/openai-timeline/
285•882542F3884314B•11h ago•292 comments

Preventing Misfolding by Preventing Folding

https://www.science.org/content/blog-post/preventing-misfolding-preventing-folding
27•surprisetalk•4d ago•1 comments

Python string literals are kinda funny

https://sebsite.pw/w/20260806-pystrings.html
53•jandeboevrie•2d ago•34 comments

Building a local positioning system to track runners using Ultra-Wideband

https://zeus.ugent.be/blog/25-26/12urenloop-uwb/
23•robinpdev•1w ago•1 comments

TinySol, a tiny solitaire game for DOS

https://classicbits.net/coding-and-software/my-software/monosol/
31•skibz•4h ago•7 comments

Triton: DirectX 11 Driver for QEMU

https://blog.getutm.app/2026/introducing-triton-directx-11-driver-for-qemu/
114•electricant•8h ago•21 comments

Monitors for Work

https://etbe.coker.com.au/2026/08/05/monitors-for-work/
63•edward•3d ago•37 comments

Making difficulty curves in games

http://www.davetech.co.uk/difficultycurves
5•hakkikonu•3d ago•1 comments

Gateway 2000's hilariously bad ads in the 90s (Part II)

https://buttondown.com/suchbadtechads/archive/gateway-2000-part-2/
86•rfarley04•9h ago•69 comments

Amazon Is Creating the Biggest Pollution Source in the Country

https://newrepublic.com/post/214111/amazon-data-center-biggest-pollution-source-entire-country
149•geox•4h ago•70 comments

US Military's cyber command unit grapples with cluster of deaths by suicide

https://www.bloomberg.com/news/articles/2026-08-06/us-military-s-cyber-command-unit-grapples-with...
196•rbanffy•12h ago•303 comments

The Unreasonable Effectiveness of Mathematics in the Natural Sciences [pdf]

https://web.njit.edu/~akansu/PAPERS/The%20Unreasonable%20Effectiveness%20of%20Mathematics%20(EP%2...
7•pseudolus•1h ago•0 comments

A physicist rigged his pet hamster’s wheel to upload to Strava

https://www.runnersworld.com/news/a73355106/hamster-wheel-strava-running/
407•aanet•3d ago•97 comments

DeepSeek V4 Flash 0731

https://arcprize.org/results/deepseek-v4-flash-0731
751•tosh•1d ago•449 comments

Hardware backdoors in some x86 CPUs

https://github.com/xoreaxeaxeax/rosenbridge
314•epestr•15h ago•92 comments

From your doorbell to your home network

https://adepts.of0x.cc/eufy-doorbell-hacking/
65•mmoogle•3d ago•7 comments

What happens if an entire class of workers loses faith in their careers

https://www.noemamag.com/why-is-everyone-in-tech-so-sad/
947•RickJWagner•1d ago•1120 comments

Voyager 1 FDS Computer Emulator

https://zaneham.github.io/voyager-fds-emulator/
66•rahen•8h ago•12 comments

BYOC Is Not Just 'Deploy into Their Cloud'

https://omnistrate.com/blog/byoc-anywhere-the-spectrum-of-bring-your-own-cloud-deployments
60•kkgupta•4d ago•10 comments

U.S. Department of Energy Launches the Genesis Open Models Initiative

https://genesisopenmodels.anl.gov/
337•moelf•23h ago•141 comments

Message your other Claude Code sessions

https://code.claude.com/docs/en/cross-session-messaging
30•mfiguiere•6h ago•13 comments