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

Comments

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

Kiel Institute Analysis: US Americans pay 96% of tariff burden

https://www.kielinstitut.de/publications/americas-own-goal-who-pays-the-tariffs-19398/
543•47282847•1h ago•418 comments

CSS Web Components for marketing sites (2024)

https://hawkticehurst.com/2024/11/css-web-components-for-marketing-sites/
36•zigzag312•2h ago•13 comments

GLM-4.7-Flash

https://huggingface.co/zai-org/GLM-4.7-Flash
184•scrlk•2h ago•49 comments

The Microstructure of Wealth Transfer in Prediction Markets

https://www.jbecker.dev/research/prediction-market-microstructure
39•jonbecker•1h ago•16 comments

Apple testing new App Store design that blurs the line between ads and results

https://9to5mac.com/2026/01/16/iphone-apple-app-store-search-results-ads-new-design/
75•ksec•1h ago•28 comments

Iterative image reconstruction using random cubic bézier strokes

https://tangled.org/luthenwald.tngl.sh/splined
29•luthenwald•4d ago•4 comments

Show HN: Pipenet – A Modern Alternative to Localtunnel

https://pipenet.dev/
15•punkpeye•1h ago•4 comments

Folding NASA Experience into an Origamist's Toolkit

https://spinoff.nasa.gov/Folding_NASA_Experience_into_an_Origamist%E2%80%99s_Toolkit
45•andsoitis•2d ago•4 comments

A decentralized peer-to-peer messaging application that operates over Bluetooth

https://bitchat.free/
446•no_creativity_•10h ago•260 comments

Radboud University selects Fairphone as standard smartphone for employees

https://www.ru.nl/en/staff/news/radboud-university-selects-fairphone-as-standard-smartphone-for-e...
418•ardentsword•9h ago•189 comments

Luxury Yacht is a desktop app for managing Kubernetes clusters

https://github.com/luxury-yacht/app
35•mooreds•4d ago•11 comments

Dead Internet Theory

https://kudmitry.com/articles/dead-internet-theory/
559•skwee357•21h ago•616 comments

What it's like to be banned from the US for fighting online hate

https://www.technologyreview.com/2026/01/19/1131384/what-its-like-to-be-banned-from-the-us-for-fi...
29•HotGarbage•43m ago•4 comments

I set all 376 Vim options and I'm still a fool

https://evanhahn.com/i-set-all-376-vim-options-and-im-still-a-fool/
48•todsacerdoti•2d ago•9 comments

Robust Conditional 3D Shape Generation from Casual Captures

https://facebookresearch.github.io/ShapeR/
24•lastdong•5h ago•1 comments

Ask HN: COBOL devs, how are AI coding affecting your work?

114•zkid18•4h ago•118 comments

Show HN: I quit coding years ago. AI brought me back

https://calquio.com/finance/compound-interest
282•ivcatcher•16h ago•376 comments

Cows Can Use Sophisticated Tools

https://nautil.us/the-far-side-had-it-all-wrong-cows-really-can-use-sophisticated-tools-1262026/
14•Tomte•52m ago•2 comments

Nepal's Mountainside Teahouses Elevate the Experience for Trekkers

https://www.smithsonianmag.com/travel/nepal-mountainside-teahouses-elevate-experience-trekkers-he...
84•bookofjoe•4d ago•34 comments

Flux 2 Klein pure C inference

https://github.com/antirez/flux2.c
397•antirez•23h ago•130 comments

Raccoons break into liquor stores, scale skyscrapers and pick locks

https://theconversation.com/raccoons-break-into-liquor-stores-scale-skyscrapers-and-pick-locks-st...
8•pseudolus•28m ago•0 comments

Provide agents with automated feedback

https://banay.me/dont-waste-your-backpressure/
159•ghuntley•2d ago•80 comments

Wikipedia: WikiProject AI Cleanup

https://en.wikipedia.org/wiki/Wikipedia:WikiProject_AI_Cleanup
192•thinkingemote•7h ago•72 comments

AVX-512: First Impressions on Performance and Programmability

https://shihab-shahriar.github.io//blog/2026/AVX-512-First-Impressions-on-Performance-and-Program...
118•shihab•5d ago•46 comments

Gladys West's vital contributions to GPS technology

https://en.wikipedia.org/wiki/Gladys_West
61•hackernj•2d ago•5 comments

Amazon is ending all inventory commingling as of March 31, 2026

https://twitter.com/ghhughes/status/2012824754319753456
384•MrBuddyCasino•5h ago•207 comments

Gas Town Decoded

https://www.alilleybrinker.com/mini/gas-town-decoded/
188•alilleybrinker•4d ago•200 comments

The Code-Only Agent

https://rijnard.com/blog/the-code-only-agent
130•emersonmacro•15h ago•56 comments

West Midlands police chief quits over AI hallucination

https://www.theregister.com/2026/01/19/copper_chief_cops_it_after/
97•YeGoblynQueenne•2h ago•69 comments

Gaussian Splatting – A$AP Rocky "Helicopter" music video

https://radiancefields.com/a-ap-rocky-releases-helicopter-music-video-featuring-gaussian-splatting
725•ChrisArchitect•23h ago•239 comments