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.

An OpenAI model has disproved a central conjecture in discrete geometry

https://openai.com/index/model-disproves-discrete-geometry-conjecture/
866•tedsanders•9h ago•647 comments

GitHub confirms breach of 3,800 repos via malicious VSCode extension

https://www.bleepingcomputer.com/news/security/github-confirms-breach-of-3-800-repos-via-maliciou...
631•Timofeibu•14h ago•225 comments

Show HN: I reverse engineered Apple's video wallpapers

https://github.com/kageroumado/phosphene
147•kageroumado•4h ago•34 comments

DOS Zone

https://dos.zone/
148•rglover•5h ago•29 comments

Colorado Amended SB051 (Age Verification Bill) to Exclude Open Source Projects

https://legiscan.com/CO/bill/SB051/2026
180•ki4jgt•8h ago•52 comments

The Letter S, by Donald Knuth (1980) [pdf]

https://gwern.net/doc/design/typography/1980-knuth.pdf
84•bambax•4h ago•8 comments

Haskell Foundation 2026 Update

https://discourse.haskell.org/t/haskell-foundation-2026-update/14136
26•azhenley•2h ago•3 comments

Flipper One Tech Specs

https://docs.flipper.net/one/general/tech-specs
304•gregsadetsky•9h ago•110 comments

New features in GCC 16: Improved error messages and SARIF output

https://developers.redhat.com/articles/2026/04/28/gcc-16-improved-error-messages-sarif-output
20•siteshwar•2d ago•0 comments

Your Most Improbable Life

https://kevinkelly.substack.com/p/your-most-improbable-life
63•jger15•2d ago•37 comments

How fast is N tokens per second really?

https://mikeveerman.github.io/tokenspeed/
340•hexagr•3d ago•77 comments

Archaeologists find Egyptian mummy buried with the 'Iliad'

https://www.openculture.com/2026/05/archaeologists-discover-ancient-egyptian-mummy-buried-with-pa...
78•diodorus•5d ago•40 comments

Reviving old scanners with an in-browser Linux VM bridged to WebUSB over USB/IP

https://yes-we-scan.app/details
31•gmac•2d ago•8 comments

OpenAI to confidentially file for IPO as soon as Friday

https://www.cnbc.com/2026/05/20/openai-ipo-filing.html
52•doppp•2h ago•7 comments

Intuit to lay off over 3k employees to refocus on AI

https://techcrunch.com/2026/05/20/intuit-to-lay-off-over-3000-employees-to-refocus-on-ai/
107•wapasta•3h ago•61 comments

Saying goodbye to asm.js

https://spidermonkey.dev/blog/2026/05/20/saying-goodbye-to-asmjs.html
337•eqrion•16h ago•137 comments

Qian Xuesen: The missile genius America lost and China gained (2025)

https://www.usni.org/magazines/naval-history/2025/december/missile-genius-america-lost-and-china-...
145•thnaks•10h ago•79 comments

Why is Inkwell stuck in review

https://www.manton.org/2026/05/19/why-is-inkwell-stuck-in.html
123•speckx•11h ago•38 comments

Recreate famous water profiles using supermarket bottled water

https://www.waterdictionary.net
4•smugglerFlynn•2d ago•0 comments

Google's AI is being manipulated. The search giant is quietly fighting back

https://www.bbc.com/future/article/20260519-google-tackles-attempts-to-hack-its-ai-results
281•tigerlily•17h ago•180 comments

SpaceX S-1

https://www.sec.gov/Archives/edgar/data/1181412/000162828026036936/spaceexplorationtechnologi.htm
291•cachecow•7h ago•223 comments

Incident Report: May 19, 2026 – GCP Account Suspension

https://blog.railway.com/p/incident-report-may-19-2026-gcp-account-outage
401•0xedb•19h ago•239 comments

Show HN: CPU-only transcription for YouTube, TikTok, X, Instagram videos

https://github.com/kouhxp/yapsnap
41•mrkn1•7h ago•15 comments

SBCL: the ultimate assembly code breadboard (2014)

https://pvk.ca/Blog/2014/03/15/sbcl-the-ultimate-assembly-code-breadboard/
135•yacin•12h ago•7 comments

Sharla Boehm, the programmer whose code underpins the Internet

https://www.scientificamerican.com/article/the-programmer-whose-code-underpins-the-internet/
112•dxs•2d ago•26 comments

What is Demand Coop and why tech workers should join one

https://cahootzcoops.com/blog/what-is-a-demand-coop
45•DeonRob•3h ago•46 comments

A Markdown-based test suite

https://blogsystem5.substack.com/p/markdown-based-test-suite
10•zdw•2d ago•0 comments

Google Declaring War on the Web

https://tante.cc/2026/05/20/on-google-declaring-war-on-the-web/
417•cdrnsf•6h ago•280 comments

PopuLoRA: Co-Evolving LLM Populations for Reasoning Self- Play

https://vmax.ai/team/populora-co-evolving-llm-populations-for-reasoning-self-play
39•AMavorParker•7h ago•6 comments

Meta blocks human rights accounts from reaching audiences in Saudi Arabia, UAE

https://www.alqst.org/ar/posts/1190
964•giuliomagnifico•15h ago•414 comments