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.

GLM-5.2 is the new leading open weights model on Artificial Analysis

https://artificialanalysis.ai/articles/glm-5-2-is-the-new-leading-open-weights-model-on-the-artif...
353•himata4113•4h ago•171 comments

Want your images back? Sure... That'll be $5!

https://www.lutr.dev/want-your-images-back-sure-that-ll-be-5-dollars
53•lutr•29m ago•17 comments

RFC 10008: The new HTTP Query Method

https://www.rfc-editor.org/info/rfc10008/
102•schappim•2h ago•49 comments

Sixty percent of US consumers say 'AI' in brand messaging is a turnoff

https://wpvip.com/future-of-the-web-2026/
244•thm•1h ago•135 comments

MicroUI – A tiny, portable, immediate-mode UI library written in ANSI C

https://github.com/rxi/microui
25•peter_d_sherman•1h ago•9 comments

Show HN: High-Res Neural Cellular Automata

https://cells2pixels.github.io/
107•esychology•4h ago•19 comments

Hacker News but for Independent Blogs

https://bubbles.town/
224•headalgorithm•5h ago•72 comments

GrapheneOS has been ported to Android 17

https://discuss.grapheneos.org/d/36469-grapheneos-has-been-ported-to-android-17-and-official-rele...
875•Cider9986•16h ago•459 comments

Running local models is good now

https://vickiboykis.com/2026/06/15/running-local-models-is-good-now/
1410•jfb•22h ago•546 comments

Show HN: Capacitor Alarm Clock

https://github.com/ArcaEge/capacitor-alarm-clock
64•arcaege•3d ago•21 comments

Abandoned and Little-Known Airfields

https://airfields-freeman.com/
35•wizardforhire•2d ago•4 comments

Humiliating IIS servers for fun and jail time

https://mll.sh/humiliating-iis-servers-for-fun-and-jail-time/
308•denysvitali•14h ago•71 comments

Map Clustering Is Not My Favorite

https://blog.greg.technology/2026/06/12/map-clustering-is-not-my-favorite.html
50•gregsadetsky•4d ago•20 comments

TIL: You can make HTTP requests without curl using Bash /dev/TCP

https://mareksuppa.com/til/bash-dev-tcp-http-without-curl/
481•mrshu•20h ago•209 comments

Subterranean fungi networks more than 100 quadrillion km in length

https://www.theguardian.com/science/2026/jun/11/arbuscular-mycorrhizal-fungi-plant-life-climate-g...
107•tosh•5d ago•28 comments

GLM 5.2 Performance Benchmarks

https://artificialanalysis.ai/models/glm-5-2
49•theanonymousone•6h ago•11 comments

Image Compression

https://www.makingsoftware.com/chapters/image-compression
11•vinhnx•3d ago•2 comments

Calvin and Hobbes and the price of integrity

https://therepublicofletters.substack.com/p/calvin-and-hobbes-and-the-price-of
483•pseudolus•21h ago•206 comments

Has AI already killed self-help nonfiction books?

https://tim.blog/2026/06/12/has-ai-already-killed-nonfiction/
349•imakwana•20h ago•403 comments

Wolfram Language and Mathematica version 15

https://writings.stephenwolfram.com/2026/06/launching-version-15-of-wolfram-language-mathematica-...
185•alok-g•14h ago•98 comments

GPT‑NL: a sovereign language model for the Netherlands

https://www.tno.nl/en/digital/artificial-intelligence/gpt-nl/
230•root-parent•19h ago•249 comments

Stop Using JWTs

https://gist.github.com/samsch/0d1f3d3b4745d778f78b230cf6061452
439•dzonga•20h ago•257 comments

From Chesterton's fence to Chesterton's gap

https://stephantul.github.io/blog/unfence/
27•stephantul•6h ago•24 comments

Semiclassical Gravity Efficiently Solves NP-Complete Problems

https://arxiv.org/abs/2606.14806
50•ascarshen•10h ago•19 comments

The founder's playbook: Building an AI-native startup

https://claude.com/blog/the-founders-playbook
122•e2e4•6h ago•118 comments

SpaceX to buy Cursor for $60B

https://www.reuters.com/legal/transactional/spacex-buy-anysphere-60-billion-2026-06-16/
1064•itsmarcelg•1d ago•1572 comments

Making 'food out of thin air' (2024)

https://www.noemamag.com/making-food-out-of-thin-air/
34•muchweight•2d ago•8 comments

But yak shaving is fun (2019)

https://parksb.github.io/en/article/32.html
276•parksb•23h ago•84 comments

A brief tour of the PDP-11, the most influential minicomputer of all time (2022)

https://arstechnica.com/gadgets/2022/03/a-brief-tour-of-the-pdp-11-the-most-influential-minicompu...
97•jensgk•2d ago•43 comments

Show HN: I built 184 free browser tools – PDF, image, dev, AI tasks, no upload

https://brevio.pro
11•ruimbarreira•3h ago•3 comments