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

Tony Hoare has died

https://blog.computationalcomplexity.org/2026/03/tony-hoare-1934-2026.html
641•speckx•2h ago•66 comments

Debian decides not to decide on AI-generated contributions

https://lwn.net/SubscriberLink/1061544/125f911834966dd0/
128•jwilk•2h ago•91 comments

Show HN: RunAnwhere – Faster AI Inference on Apple Silicon

https://github.com/RunanywhereAI/rcli
9•sanchitmonga22•12m ago•0 comments

Intel Demos Chip to Compute with Encrypted Data

https://spectrum.ieee.org/fhe-intel
141•sohkamyung•4h ago•48 comments

I built a programming language using Claude Code

https://ankursethi.com/blog/programming-language-claude-code/
10•GeneralMaximus•50m ago•11 comments

I put my whole life into a single database

https://howisfelix.today/
329•lukakopajtic•7h ago•155 comments

Launch HN: Didit (YC W26) – Stripe for Identity Verification

29•rosasalberto•2h ago•28 comments

Show HN: How I Topped the HuggingFace Open LLM Leaderboard on Two Gaming GPUs

https://dnhkng.github.io/posts/rys/
107•dnhkng•4h ago•41 comments

Meta acquires Moltbook

https://www.axios.com/2026/03/10/meta-facebook-moltbook-agent-social-network
166•mmayberry•2h ago•98 comments

Rebasing in Magit

https://entropicthoughts.com/rebasing-in-magit
124•ibobev•3h ago•82 comments

Online age-verification tools for child safety are surveilling adults

https://www.cnbc.com/2026/03/08/social-media-child-safety-internet-ai-surveillance.html
306•bilsbie•4h ago•177 comments

The Gervais Principle, or the Office According to "The Office" (2009)

https://www.ribbonfarm.com/2009/10/07/the-gervais-principle-or-the-office-according-to-the-office/
218•janandonly•3d ago•93 comments

Amazon is holding a mandatory meeting about AI breaking its systems

https://twitter.com/lukolejnik/status/2031257644724342957
208•lwhsiao•2h ago•137 comments

PgAdmin 4 9.13 with AI Assistant Panel

https://www.pgadmin.org/docs/pgadmin4/9.13/query_tool.html#ai-assistant-panel
58•__natty__•5h ago•18 comments

Sending Jabber/XMPP Messages via HTTP

https://gultsch.de/posts/xmpp-via-http/
36•inputmice•3h ago•5 comments

Yann LeCun's AI startup raises $1B in Europe's largest ever seed round

https://www.ft.com/content/e5245ec3-1a58-4eff-ab58-480b6259aaf1
368•ottomengis•6h ago•193 comments

How many options fit into a boolean?

https://herecomesthemoon.net/2025/11/how-many-options-fit-into-a-boolean/
25•luu•3d ago•5 comments

Show HN: DD Photos – open-source photo album site generator (Go and SvelteKit)

https://github.com/dougdonohoe/ddphotos
37•dougdonohoe•4h ago•9 comments

I used pulsar detection techniques to turn a phone into a watch timegrapher

https://www.chronolog.watch/timegrapher
10•tylerjaywood•2d ago•2 comments

A New Version of Our Oracle Solaris Environment for Developers

https://blogs.oracle.com/solaris/announcing-a-new-version-of-our-oracle-solaris-environment-for-d...
32•naves•2d ago•17 comments

Caxlsx: Ruby gem for xlsx generation with charts, images, schema validation

https://github.com/caxlsx/caxlsx
53•earcar•4d ago•3 comments

Practical Guide to Bare Metal C++

https://arobenko.github.io/bare_metal_cpp/#_abstract_classes
89•ibobev•3d ago•31 comments

Two Years of Emacs Solo

https://www.rahuljuliato.com/posts/emacs-solo-two-years
329•celadevra_•17h ago•122 comments

LoGeR – 3D reconstruction from extremely long videos (DeepMind, UC Berkeley)

https://loger-project.github.io
119•helloplanets•11h ago•26 comments

$3 ChromeOS Flex stick will revive old and outdated computers

https://9to5google.com/2026/03/10/this-3-chromeos-stick-will-revive-old-and-outdated-computers/
15•pentagrama•1h ago•13 comments

Lotus 1-2-3 on the PC with DOS

https://stonetools.ghost.io/lotus123-dos/
161•TMWNN•3d ago•63 comments

Traffic from Russia to Cloudflare is 60% down from last year

https://radar.cloudflare.com/traffic/ru?dateRange=52w
93•secondary_op•4h ago•47 comments

TCXO Failure Analysis

https://serd.es/2026/03/06/TCXO-failure-analysis.html
87•zdw•3d ago•38 comments

No, it doesn't cost Anthropic $5k per Claude Code user

https://martinalderson.com/posts/no-it-doesnt-cost-anthropic-5k-per-claude-code-user/
401•jnord•18h ago•292 comments

Microsoft Copilot Update Hijacks Default Browser Links

https://reclaimthenet.org/microsoft-copilot-update-hijacks-default-browser-links
9•miohtama•23m ago•0 comments