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.

Carnegie Mellon is putting computer science courses on YouTube for free

https://www.cs.cmu.edu/learn/
511•pcompeau•3h ago•86 comments

Windows 11 Is Collecting Data on Which Coding Agents and Developer Tools You Use

https://xusheng.dev/posts/windows-coding-agent-telemetry/
78•cwaffles•1h ago•36 comments

BugMeNot has closed

https://www.bugmenot.com/
245•lode•2h ago•131 comments

World's Largest Brands Infected With Malware Via Optimizely

https://blog.report-uri.com/worlds-largest-brands-infected-with-malware-via-optimizely/
124•martinald•3h ago•21 comments

How to Break into Security, Ptacek Edition (2012)

https://krebsonsecurity.com/2012/06/how-to-break-into-security-ptacek-edition/
58•ronfriedhaber•2h ago•15 comments

OpenCode Browse

https://opencode.ai/product/browse
81•mfiguiere•3h ago•37 comments

Grazing sheep in fields with solar arrays

https://news.cornell.edu/stories/2026/10/sheep-grazing-solar-fields-offers-farmers-economic-ecolo...
197•PaulHoule•6h ago•197 comments

Jiff 1.0: A datetime library for Rust

https://burntsushi.net/jiff/
288•burntsushi•7h ago•69 comments

Chemistry is Actually Geometry

https://chillphysicsenjoyer.substack.com/p/chemistry-is-actually-geometry
72•sebg•3h ago•18 comments

Frame – 31.5" color ePaper display

https://trmnl.com/blog/introducing-frame
275•geerlingguy•7h ago•194 comments

Technical issue at JPMorgan Chase triggers online banking delays for US banks

https://apnews.com/article/bank-outage-chase-wells-fargo-truist-50fee2693c22f597fa6ca51a97ef2cda
692•samk3nny•5h ago•565 comments

Formal Verification Is Not Verifiable

https://alperenkeles.com/posts/formal-verification-is-not-verifiable/
28•zdw•2d ago•3 comments

Rust changed me as a developer

https://blog.startifact.com/posts/how-rust-changed-me/
163•speckx•4h ago•104 comments

Optimizely Compromised, Served Malware on Zoom, GitLab

https://blog.report-uri.com/worlds-largest-brands-infected-with-malware-via-optimizely/
34•kristjansson•1h ago•13 comments

Launch HN: Axonnic (YC F26) – Sleeves that track fingers and estimate force

25•arshpatankar•3h ago•10 comments

Squircles

https://linebender.org/wiki/curves/squircle/
114•raphlinus•16h ago•35 comments

United Airlines experiencing a widespread system outage, airline says

https://www.cnn.com/2026/11/16/us/united-airlines-outage
139•bearsyankees•2h ago•67 comments

Show HN: Sutra-OS – A self-hosted ontology platform

https://github.com/0nelight/sutra-os
13•0nelight•56m ago•2 comments

Do Repeat Yourself

https://arcentry.com/blog/do-repeat-yourself/
5•max_sendfeld•12h ago•0 comments

Microsoft blames monster email outage on software defect introduced in July fix

https://www.theregister.com/saas/2026/11/16/microsoft-blames-monster-email-outage-on-software-def...
199•Bender•11h ago•136 comments

My Quest to push native Three.js quality match AAA Game Engines

https://ben3d.ca/blog/building-the-aaa-lighting-pipeline-in-threejs
78•bhouston•3h ago•30 comments

The Secret ThinkPad Powerbutton Code to Bring Dead Laptops Back to Life (2007)

https://masnick.com/posts/the-secret-thinkpad-powerbutton-code-to-bring-dead-laptops-back-to-life/
289•sammatilda•12h ago•114 comments

Spamhaus new email sender requirements in November

https://www.spamhaus.org/sender-guidelines/
60•computer23•2h ago•47 comments

How to Intercept HTTP/3 Traffic: QUIC and Qpack

https://interceptsuite.com/blog/intercept-http3-traffic-quic-qpack-explained/
53•anof-cyber•4h ago•4 comments

Michael Mann's 'Heat' Copyright Fight Turns on a Deal with Himself

https://copyrightlately.com/michael-mann-heat-copyright-termination/
83•speckx•6h ago•37 comments

Aristotle Expands into Rust

https://www.harmonic.fun/news/aristotle-rust-verification/
98•maufl•6h ago•47 comments

US will say "no" to global ban on killer robots

https://www.newsweek.com/us-expected-to-block-killer-robot-treaty-talks-12722369
48•madihaa•1h ago•45 comments

Strengthening the fight against online child sexual abuse

https://openai.com/index/strengthening-online-child-safety/
98•rossant•6h ago•210 comments

Jolt – Clojure that speaks C

https://jolt-lang.net/
91•michaelsbradley•7h ago•27 comments

Many of Amazon’s Black Friday and Cyber Monday “deals” offered no savings

http://groundworkcollaborative.org/news/amazons-decoy-deals-groundwork-investigation-reveals-near...
811•DeepLogin•10h ago•494 comments