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.

Twenty Years of RISC OS Open

https://www.riscosopen.org/news/articles/2026/06/20/twenty-years-of-risc-os-open
82•AlexeyBrin•3h ago•13 comments

F*: A general-purpose proof-oriented programming language

https://fstar-lang.org/
61•ducktective•3h ago•18 comments

Meshdiff – visually compare two STL versions in the browser, client-side

https://meshdiff.com/
114•projscope•4h ago•13 comments

Show HN: Bor – Open-source policy management for Linux desktops

https://getbor.dev/blog/2026-08-02-bor-v080-release/
121•eniac111•6h ago•17 comments

Fasttracker II clone in C using SDL 2

https://16-bits.org/ft2.php
39•andsoitis•4d ago•8 comments

Folding Paper Globes

https://foldingglobes.com/globes
61•dango2506•4d ago•5 comments

Artificial Intelligence: Ars Notoria and the Promise of Instant Knowledge

https://publicdomainreview.org/essay/ars-notoria/
82•jruohonen•5h ago•21 comments

A Rant About “Technology” (2005)

https://www.ursulakleguin.com/a-rant-about-technology
75•jamesgill•1h ago•27 comments

Show HN: Fuse – statically typed functional programming language

https://fuselang.org
54•the_unproven•4h ago•9 comments

Go 1.27 Interactive Tour

https://victoriametrics.com/blog/go-1-27/index.html
297•Hixon10•14h ago•145 comments

Show HN: I'm a 15 Year Old Wannabe Engineer, This Is a Cycloidal Gearbox I Built

https://github.com/tom-ilan/cycloidal_gearbox
247•tomilan•13h ago•80 comments

Norway Salmon

https://www.abc.net.au/news/2026-07-28/how-norway-s-salmon-industry-became-a-global-behemoth/1069...
36•CHB0403085482•5d ago•3 comments

Great Question (YC W21) Is Hiring Senior Demand Gen Manager

https://www.ycombinator.com/companies/great-question/jobs/YutDxyf-senior-demand-generation-manager
1•nedwin•4h ago

Holocloth

https://holocloth.vercel.app
83•ingve•2d ago•16 comments

Rust All Hands 2026 Retrospective

https://blog.rust-lang.org/inside-rust/2026/07/31/all-hands-2026-retrospective/
34•dcminter•5h ago•11 comments

Diátaxis

https://diataxis.fr/
437•ryanseys•19h ago•50 comments

Show HN: Syncular – offline-first SQL sync with TypeScript and Rust cores

https://github.com/syncular/syncular
57•quambo•6h ago•20 comments

MkLinux and the pimped-out Apple Workgroup Server 9150

http://oldvcr.blogspot.com/2026/08/mklinux-and-pimped-out-apple-workgroup.html
83•goldenskye•12h ago•8 comments

Seedance 2.5

https://seed.bytedance.com/en/blog/one-take-creation-flexible-referencing-introducing-seedance-2-5
403•njaremko•19h ago•222 comments

US Treasury undertakes historic intervention in yen market

https://www.ft.com/content/0f9b2fe7-bde4-4f5f-b49e-93ccb5da9ea8
128•23pointsNorth•5h ago•81 comments

Show HN: Katharos Functional programming and CSP-style concurrency for Python

https://github.com/kamalfarahani/katharos
20•kamalf•5h ago•3 comments

ESP32-C3 SuperMini antenna modification

https://peterneufeld.wordpress.com/2025/03/04/esp32-c3-supermini-antenna-modification/
35•ta988•9h ago•6 comments

Running Kimi K3 on MI355X at Better Performance per Dollar Than B300

https://www.wafer.ai/blog/kimi-k3-mi355x
175•ilreb•11h ago•90 comments

Wikimedia Foundation refuses union recognition, hires union-busting law firm

https://en.wikipedia.org/wiki/Wikipedia:Wikipedia_Signpost/2026-08-02/News_and_notes
244•akolbe•4h ago•210 comments

ASRock BC-250: Building the Budget Steam Machine

https://plug-world.com/posts/2026/asrock-bc250-the-budget-steam-machine/
95•plug_world•14h ago•39 comments

Elena, a library for building Progressive Web Components

https://elenajs.com/
60•brianzelip•3d ago•7 comments

Deep-sea vehicles spot 'alien' sharks deep beneath the waves in the Pacific

https://www.science.org/content/article/deep-sea-vehicles-spot-alien-sharks-deep-beneath-waves-pa...
87•pkaeding•13h ago•43 comments

When random.bytes() runs but doesn't work

https://insider.btcpp.dev/p/when-randombytes-runs-but-doesnt
80•Funes-•13h ago•40 comments

Unraveling the mysteries of habit formation

https://www.kyoto-u.ac.jp/en/research-news/2026-07-28
101•hhs•17h ago•43 comments

Cyberscript

https://cyberscript.dev
41•dtj1123•8h ago•42 comments