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.

Anthropic’s Nasdaq debut

https://www.reuters.com/business/finance/anthropics-historic-debut-put-ais-promise-peril-wall-st-...
943•wslh•9h ago•1857 comments

Gemini 4 Neon is the new #1 on the Models Engineering Index

https://git-aarvin.github.io/mei/
154•hn-aarvin•3h ago•92 comments

Pancreatic cancer halted by virus injection in three patients

https://www.newscientist.com/article/2528235-pancreatic-cancer-halted-by-virus-injection-in-three...
610•cybermango•9h ago•94 comments

OpenSSL: Buffer overflow in EVP_EncodeBlock() (CVE-2026-121481, CVSS 9.8)

https://github.com/openssl/openssl/pull/33652
19•JacobHenner•43m ago•0 comments

Claude solves two open problems in the physics of black holes

https://www.anthropic.com/research/claude-black-hole-physics
404•cybermango•9h ago•184 comments

How to CAD Almost Anything

https://ocw.mit.edu/courses/res-16-002-how-to-cad-almost-anything-january-iap-2024/
147•o4c•2d ago•36 comments

Garage Door Spam

https://blog.harrison.page/garage-door-spam/
768•harrisonpage•3d ago•320 comments

Synology Security Advisory

https://www.synology.com/en-uk/security/advisory/Synology_SA_26_21
109•choult•4h ago•76 comments

RegExr: Temporarily Offline

https://regexr.com/
56•somebudyelse•4h ago•28 comments

The 98% Slot Machine: How Paid Advertising Became an Extraction Tax

https://globalcommercegraph.com/writing/the-ninety-eight-percent-slot-machine
214•dev1one1•8h ago•112 comments

Vint Cerf on why TCP/IP was never patented

https://seremot.com/p/vint-cerf-on-why-tcpip-was-never
14•emot•1h ago•3 comments

Someone reported java4shell bug in September 2026

https://github.com/openjdk/jdk/pull/32781
380•notmine1337•14h ago•97 comments

Should governments slow frontier AI? Jacob Coxon and Robin Hanson debate [video]

https://www.youtube.com/watch?v=lwfewYL7X0o
81•sandslash•7h ago•149 comments

Show HN: Cornhole News – A Hacker News inspired site for news across the Midwest

https://cornholenews.news
193•cornholemedia•11h ago•92 comments

Visa, Mastercard and JPMorgan Customer Data Leaked by Hackers

https://www.wsj.com/finance/banking/visa-mastercard-and-jpmorgan-customer-data-leaked-by-hackers-...
107•mikhael•3h ago•34 comments

Talking Venice with Mahesh Subramony at AMD In-Depth

https://chipsandcheese.com/p/talking-venice-with-mahesh-subramony
11•rbanffy•2d ago•0 comments

Weight-Space Programming builds neural networks like a 1990s researcher

https://notesbylex.com/weight-space-programming-1990s
18•lexandstuff•2d ago•1 comments

Postgres 19 is out, and it's available on Neon and Databricks Lakebase

https://www.databricks.com/blog/postgresql-19-available-lakebase
7•sp_from_db•2h ago•3 comments

UK government forced to admit it issued Apple a secret encryption order

https://macanorak.com/uk-government-forced-to-admit-it-issued-apple-a-secret-encryption-order/
529•Terretta•10h ago•239 comments

Making 8-page foldable zines from a single A4 sheet in the browser

https://krthr.co/paper-folds-and-whats-new-in-fanzines-app/
254•krthr•13h ago•56 comments

IRA Velinsky, industrial designer for Commodore and Atari

https://dfarq.homeip.net/ira-velinsky-industrial-designer-of-the-commodore-64/
5•onename•1d ago•0 comments

Launch HN: Onlook (YC W25) – An open-source developer tool for designers

https://github.com/onlook-dev/onlook/
88•D_R_Farrell•10h ago•68 comments

Nintendo takes Picofly firmware down from GitHub [video]

https://www.youtube.com/watch?v=-TLCGUpoD6c
258•cowlevel•1d ago•104 comments

Computer Graphics from Scratch (2021)

https://www.gabrielgambetta.com/computer-graphics-from-scratch/index.html
59•ibobev•2d ago•12 comments

Rebuilding my local voice assistant pipeline

https://blog.platypush.tech/article/Rewriting-my-voice-assistant-pipeline
62•todsacerdoti•5h ago•12 comments

An Oregon library ditched Dewey Decimal and got people excited about books again

https://www.fastcompany.com/91597520/oregon-library-ditched-dewey-decimal-wayfinding-system
206•bookofjoe•2d ago•144 comments

How the European Commission rolled out Matrix to more than 40k staff

https://element.io/blog/how-the-european-commission-rolled-out-matrix-to-more-than-40-000-staff/
669•liotier•15h ago•326 comments

Do not buy RAM, compress

https://curiousbits.nl/blog/do-not-buy-ram-compress/
263•Ecno92•17h ago•215 comments

Reverse-Engineering Kevin J. Lang's Lost OCaml Code in Apache DataSketches

https://www.tisonkun.io/posts/ai-repair-program/
36•tison•3d ago•2 comments

What's New in PHP 8.6

https://www.php.net/releases/8.6/en.php
278•netol•17h ago•128 comments