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•6mo ago

Comments

LegionMammal978•6mo 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•6mo 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•6mo 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.

Be Like Clippy

https://be-clippy.com/
22•Aloha•45m ago•6 comments

Zero knowlege proof of compositeness

https://www.johndcook.com/blog/2025/11/29/zkp-composite/
43•ColinWright•2h ago•5 comments

Student Perceptions of AI Coding Assistants in Learning

https://arxiv.org/abs/2507.22900
26•victorbuilds•2h ago•24 comments

Hardening the C++ Standard Library at scale

https://queue.acm.org/detail.cfm?id=3773097
72•ndesaulniers•6d ago•27 comments

Show HN: Network Monitor – a GUI to spot anomalous connections on your Linux

39•grigio•5d ago•13 comments

Hachi: An Image Search Engine

https://eagledot.xyz/hachi.md.html
99•warangal•6h ago•13 comments

Bronze Age mega-settlement in Kazakhstan has advanced urban planning, metallurgy

https://archaeologymag.com/2025/11/bronze-age-mega-settlement-in-kazakhstan/
92•CGMthrowaway•1w ago•14 comments

Framework Computer Now Sponsoring LVFS / Fwupd Development

https://www.phoronix.com/news/Framework-Sponsoring-LVFS
43•LorenDB•1h ago•0 comments

Electric vehicle sales are booming in South America – without Tesla

https://www.reuters.com/sustainability/climate-energy/electric-vehicle-sales-are-booming-south-am...
41•breve•1h ago•27 comments

DNS LOC Record (2014)

https://blog.cloudflare.com/the-weird-and-wonderful-world-of-dns-loc-records/
111•mikejeays•6h ago•33 comments

The CRDT Dictionary: A Field Guide to Conflict-Free Replicated Data Types

https://www.iankduncan.com/engineering/2025-11-27-crdt-dictionary/
96•birdculture•8h ago•6 comments

An update on the Farphone's battery

https://far.computer/battery-update/
48•birdculture•2h ago•25 comments

AccessOwl (YC S22) Is Hiring a Technical Account Manager (IAM)

https://www.ycombinator.com/companies/accessowl/jobs/dGC3pcO-technical-account-manager-identity-a...
1•philipeller•3h ago

Iceland declares ocean-current instability a national security risk

https://edition.cnn.com/2025/11/15/climate/iceland-warming-current-amoc-collapse-threat
256•donohoe•5h ago•107 comments

Anthony Bourdain's Lost Li.st's

https://bourdain.greg.technology/
165•gregsadetsky•3d ago•48 comments

System 7 natively boots on the Mac mini G4

https://macos9lives.com/smforum/index.php?topic=7711.0
302•ibobev•17h ago•91 comments

Ported freetype, fontconfig, harfbuzz, and graphite to Fil-C

https://twitter.com/filpizlo/status/1994563191528198653
22•jhatemyjob•1h ago•3 comments

Plinko PIR Tutorial

https://vitalik.eth.limo/general/2025/11/25/plinko.html
6•sygma•3d ago•0 comments

WinApps: Run Windows apps as if they were a part of the native Linux OS

https://github.com/winapps-org/winapps
289•klaussilveira•4d ago•139 comments

WebR – R in the Browser

https://webr.sh/
86•creata•5d ago•27 comments

Airbus A320 – intense solar radiation may corrupt data critical for flight

https://www.airbus.com/en/newsroom/press-releases/2025-11-airbus-update-on-a320-family-precaution...
461•pyrophoenix•22h ago•149 comments

Major AI conference flooded with peer reviews written by AI

https://www.nature.com/articles/d41586-025-03506-6
142•_____k•5h ago•92 comments

Building road signs at home using a Cricut Machine

https://annanay.dev/build-a-signboard/
27•annanay•3d ago•13 comments

Show HN: Zero-power photonic language model–code

https://zenodo.org/records/17764289
4•damir00•1h ago•1 comments

Garfield's Proof of the Pythagorean Theorem

https://en.wikipedia.org/wiki/Garfield%27s_proof_of_the_Pythagorean_theorem
151•benbreen•13h ago•75 comments

It's Always the Process, Stupid

https://its.promp.td/its-always-the-process-stupid/
235•DocIsInDaHouse•6h ago•93 comments

We're learning more about what Vitamin D does to our bodies

https://www.technologyreview.com/2025/11/21/1128206/vitamin-d-bodies-bone-health-immune/
94•Brajeshwar•3h ago•67 comments

Show HN: Explore what the browser exposes about you

https://neberej.github.io/exposedbydefault/
179•coffeecoders•5d ago•65 comments

Every mathematician has only a few tricks (2020)

https://mathoverflow.net/questions/363119/every-mathematician-has-only-a-few-tricks
226•nill0•18h ago•60 comments

FBI RFP for tool to scrape Gab, Parler, 8Kun, and Telegram (5k licenses) [pdf]

https://vault.fbi.gov/contract-15f06722c0000258
8•sans_souse•20m ago•1 comments