frontpage.
newsnewestaskshowjobs

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.

Qwenputer: A functioning, deterministic RISC-V CPU inside Qwen3.5

https://divagr.com/blog/qwenputer
484•csmantle•10h ago•101 comments

Zero click, silent, remote Android DoS

https://smsofdeath.com/
90•MarkBlah•3h ago•46 comments

Why is this fingerprinting script creating bioweapons?

https://nullpt.rs/fingerprinting-bioweapons
1258•hazebooth•17h ago•241 comments

Getting debug access on a Brother printer over Telnet

https://inventor7777.github.io/blog/2026/10/22/debug-access-on-brother/
57•inventor7777•2d ago•14 comments

Forging a Microsoft Edge Full Chain with Logic Bugs Only

https://blog.orange.tw/posts/2026-10-the-last-proof-of-human-craft-browser-full-chain/
67•austinallegro•3h ago•16 comments

OpenAI's agents talked to each other through the CPU Cache

https://the-decoder.com/openais-isolated-ai-agents-found-ways-to-talk-to-each-other-through-cpu-c...
169•limbicsystem•2d ago•81 comments

StackOverflow now gets fewer than 1000 questions a month

https://data.stackexchange.com/stackoverflow/query/1926661#graph?t=1
478•babelfish•11h ago•399 comments

A Health Update

https://furbo.org/2026/10/28/a-health-update/
265•frizlab•13h ago•42 comments

MiniLake Is a Local Databricks API Emulator with SQL, Delta Lake and Spark

https://dmux.github.io/minilake/
19•kermatt•1d ago•2 comments

A new faster algorithm to compute 64-bit signed floor division

https://www.benjoffe.com/fast-floordiv
70•benjoffe•2d ago•5 comments

CNC Stone Carving

https://carmelitegothic.com/cnc-stone-carving/
476•bschne•20h ago•131 comments

GitLab Security Incident: Attempted Exploitation of CVE-2026-97229

https://alpinelinux.org/posts/GitLab-security-incident-CVE-2026-97229.html
183•sashk•10h ago•89 comments

Claude Code regularly sends each background agent’s transcript to its model

https://gist.github.com/flamerix-ai/c3905705cc4205e5de3011fa2e74efce
393•NikZaal•7h ago•137 comments

The Grid, a factory-scale robot in Massachusetts that builds PCBs on demand

https://www.circuithub.com/post/unveiling-the-grid
505•seddona•2d ago•229 comments

Formlabs Studio 1 $699 Resin Printer

https://formlabs.com/products/form-studio-1-basic-founders-edition/
189•mhb•13h ago•125 comments

Gemini 4 Carbon

https://blog.google/innovation-and-ai/models-and-research/gemini-models/introducing-gemini-4-carbon/
941•acossta•17h ago•759 comments

Treap (Cartesian Tree)

https://cp-algorithms.com/data_structures/treap.html
29•vismit2000•2d ago•3 comments

Why birds can fly over Mount Everest (2020)

https://lede-v2.nautil.us/why-birds-can-fly-over-mount-everest-237864
167•andsoitis•4d ago•34 comments

Cuba is skipping its November 1, 2026 clock change and staying on DST until 2027

https://www.timeanddate.com/news/time/cuba-keeps-dst-until-nov-2027.html
65•n_plus_1_acc•2h ago•121 comments

Spain train crash: What we know after two trains crashed with dozens feared dead

https://www.bbc.com/news/articles/cm8xz7pkd0jjo
18•ZeljkoS•1h ago•6 comments

Human-enhanced tsunami hazard in large lakes

https://www.nature.com/articles/s41467-026-78272-8
39•gumby•2d ago•3 comments

MacBook Pro with PROLED XDR Display and Touch

https://www.apple.com/macbook-pro/proled-xdr-display/
579•etothet•17h ago•983 comments

Nixpkgs for the Front End Impaired

https://fzakaria.com/2026/10/12/nixpkgs-for-the-frontend-impaired
68•surprisetalk•2d ago•13 comments

AlpineBSD

https://wiki.alpinebsd.org
219•bradley_taunt•20h ago•210 comments

Apple's git still trusts the compromised eMudhra certificates

https://emudhra.we-have-a-problem.com/apple.html
1137•galadran•23h ago•397 comments

Scaling Hierarchical Networks

https://www.cartesia.ai/blog/from-tokens-to-bytes-part-1
73•guybedo•16h ago•4 comments

Nango (YC W23) Is Hiring Across Eng, FDE, Marketing, DevRel

https://nango.dev/careers
1•bastienbeurier•13h ago

Dayjob: Tax – evaluating AI agents on 50 professional tax assignments

https://surgehq.ai/blog/dayjob-tax
238•landonxi•18h ago•153 comments

Spiders Spin 'Silk Dope' into Nature's Toughest Material

https://www.quantamagazine.org/how-spiders-spin-silk-dope-into-natures-toughest-material-20261028/
67•ibobev•16h ago•6 comments

The Agent SDK

https://cursor.com/blog/agent-sdk
131•torutofu•20h ago•125 comments