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•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.

Railway Blocked by Google Cloud

https://status.railway.com/?date=20260519
172•aarondf•2h ago•51 comments

Gemini 3.5 Flash

https://blog.google/innovation-and-ai/models-and-research/gemini-models/gemini-3-5/
599•spectraldrift•8h ago•452 comments

I’ve built a virtual museum with nearly every operating system you can think of

https://virtualosmuseum.org/
607•andreww591•10h ago•146 comments

Google changes its search box

https://blog.google/products-and-platforms/products/search/search-io-2026/
390•berkeleyjunk•7h ago•560 comments

Remove–AI–Watermarks – CLI and library for removing AI watermarks from images

https://github.com/wiltodelta/remove-ai-watermarks
130•janalsncm•3h ago•77 comments

OpenAI Adopts Google's SynthID Watermark for AI Images with Verification Tool

https://openai.com/index/advancing-content-provenance/
209•smooke•6h ago•105 comments

Show HN: Forge – Guardrails take an 8B model from 53% to 99% on agentic tasks

https://github.com/antoinezambelli/forge
284•zambelli•14h ago•104 comments

The Mercury logic programming system

https://github.com/Mercury-Language/mercury
21•Antibabelic•1d ago•1 comments

Mistral AI acquires Emmi AI

https://www.emmi.ai/news/mistral-ai-acquires-emmi-ai
172•doener•7h ago•44 comments

GitHub is investigating unauthorized access to their internal repositories

https://twitter.com/github/status/2056884788179726685
152•splenditer•2h ago•34 comments

Apple unveils new accessibility features

https://www.apple.com/newsroom/2026/05/apple-unveils-new-accessibility-features-and-updates-with-...
603•interpol_p•14h ago•311 comments

Minnesota becomes first state to ban prediction markets

https://www.npr.org/2026/05/19/nx-s1-5821265/minnesota-ban-prediction-markets
475•ortusdux•7h ago•146 comments

Growing Neural Cellular Automata

https://distill.pub/2020/growing-ca/
73•pulkitsh1234•2d ago•6 comments

I’ve joined Anthropic

https://twitter.com/karpathy/status/2056753169888334312
1183•dmarcos•11h ago•487 comments

Tool mapping 90 companies in the photonics and CPO supply chain

https://leonardo-boquillon.com/photonic-cop-supply-chain
28•lboquillon•2d ago•2 comments

Lisp in Web-Based Applications (2001)

https://sep.turbifycdn.com/ty/cdn/paulgraham/bbnexcerpts.txt
43•bschne•1d ago•3 comments

The two oldest printing presses

https://museumplantinmoretus.be/en/worlds-two-oldest-printing-presses
22•janpot•1d ago•4 comments

CISA Admin Leaked AWS GovCloud Keys on GitHub

https://krebsonsecurity.com/2026/05/cisa-admin-leaked-aws-govcloud-keys-on-github/
408•LelouBil•18h ago•168 comments

Dumb ways for an open source project to die

https://nesbitt.io/2026/05/19/dumb-ways-for-an-open-source-project-to-die.html
155•chmaynard•7h ago•90 comments

Gemini CLI will stop working from June 18, 2026

https://developers.googleblog.com/an-important-update-transitioning-gemini-cli-to-antigravity-cli/
66•primaprashant•8h ago•23 comments

Unusual uses of OEIS sequences on GitHub

https://www.jeremykun.com/shortform/2026-04-13-0700/
18•surprisetalk•1d ago•1 comments

Why is almost everyone right-handed? A new study connects it to bipedalism

https://www.ox.ac.uk/news/2026-05-15-why-is-almost-everyone-right-handed-the-answer-may-lie-in-ho...
94•gmays•11h ago•150 comments

Microsoft is 1.84 Peters, Google is 0.66. What's the Peter unit?

https://github.com/zozo123/peter-gt-your-org
10•zozo123OR0x90•2d ago•1 comments

Disney erased FiveThirtyEight

https://www.natesilver.net/p/disney-erased-fivethirtyeight
328•7777777phil•7h ago•195 comments

Copy Fail, Dirty Frag, and Fragnesia kernel vulnerabilities

https://www.gentoo.org/news/2026/05/19/copy-fail-fragnesia-vulnerabilities.html
113•akhuettel•10h ago•42 comments

The foundations of a provably secure operating system (PSOS) (1979) [pdf]

http://www.csl.sri.com/users/neumann/psos.pdf
122•rurban•1d ago•83 comments

The TTY Demystified (2008)

https://www.linusakesson.net/programming/tty/index.php
43•20after4•7h ago•8 comments

Intro to TLA+ for the LLM Era: Prompt Your Way to Victory

https://emptysqua.re/blog/intro-to-tla-plus-for-the-llm-era/
114•zdw•2d ago•26 comments

Hanoi’s humble beer glass and the memory of a nation

https://sundaylongread.com/2026/05/15/hanois-humble-beer-glass-and-the-memory-of-a-nation/
124•NaOH•1d ago•37 comments

Gemini Omni

https://deepmind.google/models/gemini-omni/
276•meetpateltech•8h ago•112 comments