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.

Launch HN: Freestyle: Sandboxes for AI Coding Agents

https://www.freestyle.sh
37•benswerd•1h ago•9 comments

Germany Doxes "UNKN," Head of RU Ransomware Gangs REvil, GandCrab

https://krebsonsecurity.com/2026/04/germany-doxes-unkn-head-of-ru-ransomware-gangs-revil-gandcrab/
154•Bender•3h ago•64 comments

I won't download your app. The web version is a-ok

https://www.0xsid.com/blog/wont-download-your-app
571•ssiddharth•3h ago•312 comments

sc-im Spreadsheets in Your Terminal

https://github.com/andmarti1424/sc-im
50•m-hodges•1h ago•5 comments

A Cryptography Engineer's Perspective on Quantum Computing Timelines

https://words.filippo.io/crqc-timeline/
67•thadt•2h ago•9 comments

Claude Code is unusable for complex engineering tasks with the Feb updates

https://github.com/anthropics/claude-code/issues/42796
261•StanAngeloff•3h ago•160 comments

81yo Dodgers fan can no longer get tickets because he doesn't have a smartphone

https://twitter.com/Suzierizzo1/status/2040864617467924865
156•josephcsible•1h ago•131 comments

Book Review: There Is No Antimemetics Division

https://www.stephendiehl.com/posts/no_antimimetics/
95•ibobev•3h ago•71 comments

Reducto releases Deep Extract

https://reducto.ai/blog/reducto-deep-extract-agent
16•raunakchowdhuri•1h ago•1 comments

Sky – an Elm-inspired language that compiles to Go

https://github.com/anzellai/sky
18•whalesalad•2h ago•0 comments

What Being Ripped Off Taught Me

https://belief.horse/notes/what-being-ripped-off-taught-me/
203•doctorhandshake•4h ago•126 comments

Show HN: I built a tiny LLM to demystify how language models work

https://github.com/arman-bd/guppylm
767•armanified•17h ago•115 comments

Microsoft hasn't had a coherent GUI strategy since Petzold

https://www.jsnover.com/blog/2026/03/13/microsoft-hasnt-had-a-coherent-gui-strategy-since-petzold/
711•naves•1d ago•490 comments

An open-source 240-antenna array to bounce signals off the Moon

https://moonrf.com/
223•hillcrestenigma•14h ago•45 comments

PostHog (YC W20) Is Hiring

1•james_impliu•4h ago

Gemma 4 on iPhone

https://apps.apple.com/nl/app/google-ai-edge-gallery/id6749645337
793•janandonly•22h ago•222 comments

The Last Quiet Thing

https://www.terrygodier.com/the-last-quiet-thing
21•coinfused•2d ago•4 comments

France pulls last gold held in US for $15B gain

https://www.mining.com/france-pulls-last-gold-held-in-us-for-15b-gain/
472•teleforce•9h ago•261 comments

Show HN: GovAuctions lets you browse government auctions at once

https://www.govauctions.app/
4•player_piano•1h ago•3 comments

The 1987 game “The Last Ninja” was 40 kilobytes

https://twitter.com/exQUIZitely/status/2040777977521398151
240•keepamovin•14h ago•152 comments

Show HN: Real-time AI (audio/video in, voice out) on an M3 Pro with Gemma E2B

https://github.com/fikrikarim/parlor
222•karimf•23h ago•25 comments

One ant for $220: The new frontier of wildlife trafficking

https://www.bbc.com/news/articles/cg4g44zv37qo
94•gmays•4d ago•24 comments

LÖVE: 2D Game Framework for Lua

https://github.com/love2d/love
381•cl3misch•2d ago•193 comments

Signals, the push-pull based algorithm

https://willybrauner.com/journal/signal-the-push-pull-based-algorithm
126•mpweiher•2d ago•32 comments

Drop, formerly Massdrop, ends most collaborations and rebrands under Corsair

https://drop.com/
109•stevebmark•13h ago•52 comments

Running Gemma 4 locally with LM Studio's new headless CLI and Claude Code

https://ai.georgeliu.com/p/running-google-gemma-4-locally-with
365•vbtechguy•1d ago•92 comments

When Virality Is the Message: The New Age of AI Propaganda

https://time.com/article/2026/04/02/when-virality-is-the-message-the-new-age-of-ai-propaganda/
48•virgildotcodes•3h ago•39 comments

Sheets Spreadsheets in Your Terminal

https://github.com/maaslalani/sheets
164•_____k•2d ago•42 comments

Music for Programming

https://musicforprogramming.net
300•merusame•23h ago•152 comments

Show HN: Gemma Gem – AI model embedded in a browser – no API keys, no cloud

https://github.com/kessler/gemma-gem
134•ikessler•17h ago•18 comments