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

Comments

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

Simplifying Vulkan One Subsystem at a Time

https://www.khronos.org/blog/simplifying-vulkan-one-subsystem-at-a-time
87•amazari•2h ago•8 comments

I started programming when I was 7. I'm 50 now and the thing I loved has changed

https://www.jamesdrandall.com/posts/the_thing_i_loved_has_changed/
36•jamesrandall•45m ago•25 comments

Oxide raises $200M Series C

https://oxide.computer/blog/our-200m-series-c
208•igrunert•1h ago•109 comments

Clean-room implementation of Half-Life 2 on the Quake 1 engine

https://code.idtech.space/fn/hl2
162•klaussilveira•4h ago•27 comments

Parse, Don't Validate (2019)

https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/
20•shirian•1h ago•0 comments

Show HN: I built a macOS tool for network engineers – it's called NetViews

https://www.netviews.app
43•n1sni•10h ago•8 comments

Frontier AI agents violate ethical constraints 30–50% of time, pressured by KPIs

https://arxiv.org/abs/2512.20798
443•tiny-automates•12h ago•293 comments

Jury told that Meta, Google 'engineered addiction' at landmark US trial

https://techxplore.com/news/2026-02-jury-told-meta-google-addiction.html
199•geox•1h ago•163 comments

Redefining Go Functions

https://pboyd.io/posts/redefining-go-functions/
21•todsacerdoti•1h ago•2 comments

The US is flirting with its first-ever population decline

https://www.bloomberg.com/news/articles/2026-01-30/trump-immigration-crackdown-could-shrink-us-po...
37•alephnerd•48m ago•69 comments

Europe's $24T Breakup with Visa and Mastercard Has Begun

https://europeanbusinessmagazine.com/business/europes-24-trillion-breakup-with-visa-and-mastercar...
58•NewCzech•4h ago•19 comments

America's $1T AI Gamble

https://www.apricitas.io/p/americas-1t-ai-gamble
13•m-hodges•2h ago•2 comments

Qwen-Image-2.0: Professional infographics, exquisite photorealism

https://qwen.ai/blog?id=qwen-image-2.0
193•meetpateltech•6h ago•117 comments

Show HN: Distr 2.0 – A year of learning how to ship to customer environments

https://github.com/distr-sh/distr
37•louis_w_gk•3h ago•9 comments

Rust implementation of Mistral's Voxtral Mini 4B Realtime runs in your browser

https://github.com/TrevorS/voxtral-mini-realtime-rs
345•Curiositry•14h ago•45 comments

Vercel's CEO offers to cover expenses of 'Jmail'

https://www.threads.com/@qa_test_hq/post/DUkC_zjiGQh
83•vinnyglennon•55m ago•66 comments

A method and calculator for building foamcore drawer organisers

https://capnfabs.net/posts/foamcore-would-be-a-sick-name-for-a-music-genre/
8•evakhoury•20h ago•3 comments

Pure C, CPU-only inference with Mistral Voxtral Realtime 4B speech to text model

https://github.com/antirez/voxtral.c
254•Curiositry•14h ago•22 comments

Discord Alternatives, Ranked

https://taggart-tech.com/discord-alternatives/
498•pseudalopex•20h ago•313 comments

RLHF from Scratch

https://github.com/ashworks1706/rlhf-from-scratch
24•onurkanbkrc•4h ago•1 comments

80386 Barrel Shifter

https://nand2mario.github.io/posts/2026/80386_barrel_shifter/
42•jamesbowman•2d ago•4 comments

Why is the sky blue?

https://explainers.blog/posts/why-is-the-sky-blue/
719•udit99•1d ago•242 comments

Zulip.com Values

https://zulip.com/values/
197•nothrowaways•15h ago•46 comments

Disruption with Some GitHub Services

https://www.githubstatus.com/incidents/wkgqj4546z1c
50•gpi•41m ago•15 comments

Converting a $3.88 analog clock from Walmart into a ESP8266-based Wi-Fi clock

https://github.com/jim11662418/ESP8266_WiFi_Analog_Clock
576•tokyobreakfast•23h ago•179 comments

Show HN: Elysia JIT "Compiler", why it's one of the fastest JavaScript framework

https://elysiajs.com/internal/jit-compiler
36•saltyaom•2d ago•8 comments

MIT Technology Review has confirmed that posts on Moltbook were fake

https://www.technologyreview.com/2026/02/06/1132448/moltbook-was-peak-ai-theater/
208•helloplanets•2d ago•101 comments

Discord will require a face scan or ID for full access next month

https://www.theverge.com/tech/875309/discord-age-verification-global-roll-out
1898•x01•1d ago•1820 comments

Lance table format explained simply, stupid (Animated)

https://tontinton.com/posts/lance/
8•tontinton•2d ago•0 comments

Hard-braking events as indicators of road segment crash risk

https://research.google/blog/hard-braking-events-as-indicators-of-road-segment-crash-risk/
347•aleyan•22h ago•512 comments