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.

Show HN: I built a synth for my daughter

https://bitsnpieces.dev/posts/a-synth-for-my-daughter/
540•random_moonwalk•5d ago•109 comments

Google is killing the open web, part 2

https://wok.oblomov.eu/tecnologia/google-killing-open-web-2/
191•akagusu•2h ago•129 comments

A new book recovers the origins of Effective Altruism

https://newrepublic.com/article/202433/happened-effective-altruism
12•Thevet•30m ago•0 comments

Replicate is joining Cloudflare

https://replicate.com/blog/replicate-cloudflare
191•bfirsh•3h ago•51 comments

The Baumol Effect and Jevons paradox are related

https://www.a16z.news/p/why-ac-is-cheap-but-ac-repair-is
12•cubefox•31m ago•3 comments

FreeMDU: Open-source Miele appliance diagnostic tools

https://github.com/medusalix/FreeMDU
148•Medusalix•4h ago•30 comments

WebTransport is almost here to allow UDP-like exchange in the browser

https://developer.mozilla.org/en-US/docs/Web/API/WebTransport_API
23•BinaryIgor•1w ago•4 comments

WBlock: A New Ad-Blocker for Safari

https://github.com/0xCUB3/wBlock
42•InfiniteVortex•2h ago•30 comments

Celtic Code: Drawing Knots with Python

https://2earth.github.io/website/20250202.html
64•HansardExpert•2w ago•14 comments

WeatherNext 2: Our most advanced weather forecasting model

https://blog.google/technology/google-deepmind/weathernext-2/
43•meetpateltech•3h ago•13 comments

Project Gemini

https://geminiprotocol.net/
80•andsoitis•2h ago•67 comments

Cities Panic over Having to Release Mass Surveillance Recordings

https://www.nakedcapitalism.com/2025/11/cities-panic-over-having-to-release-mass-surveillance-rec...
70•pavel_lishin•44m ago•5 comments

Every log must fire: applying Chekhov's gun to cybersecurity incident reports

https://andreafortuna.org/2025/11/17/chekhovs-gun-and-cybersecurity-incident-reports
4•speckx•23m ago•0 comments

Ned: ImGui Text Editor with GL Shaders

https://github.com/nealmick/ned
60•klaussilveira•6h ago•20 comments

Show HN: Reverse perspective camera for OpenGL (Three.js)

https://github.com/bntre/reverse-perspective-threejs
40•bntr•1w ago•3 comments

Living my best Sun Microsystems ecosystem life in 2025

https://www.osnews.com/story/143570/living-my-best-sun-microsystems-ecosystem-life-in-2025/
45•birdculture•1h ago•14 comments

C++ implementation of SIP, ICE, TURN and related protocols

https://github.com/resiprocate/resiprocate
66•mooreds•1w ago•6 comments

How to escape the Linux networking stack

https://blog.cloudflare.com/so-long-and-thanks-for-all-the-fish-how-to-escape-the-linux-networkin...
5•meysamazad•2h ago•0 comments

Deploying Temporal on AWS ECS with Terraform

https://papnori.github.io/posts/temporal-ecs-terraform/
22•norapap•1w ago•7 comments

Craft Chrome Devtools Protocol (CDP) commands with the new command editor

https://developer.chrome.com/blog/cdp-command-editor
90•keepamovin•1w ago•22 comments

Building a Simple Search Engine That Works

https://karboosx.net/post/4eZxhBon/building-a-simple-search-engine-that-actually-works
234•freediver•14h ago•67 comments

Giving C a Superpower

https://hwisnu.bearblog.dev/giving-c-a-superpower-custom-header-file-safe_ch/
171•mithcs•7h ago•140 comments

Heretic: Automatic censorship removal for language models

https://github.com/p-e-w/heretic
702•melded•1d ago•336 comments

A file format uncracked for 20 years

https://landaire.net/a-file-format-uncracked-for-20-years/
280•todsacerdoti•1w ago•54 comments

Listen to Database Changes Through the Postgres WAL

https://peterullrich.com/listen-to-database-changes-through-the-postgres-wal
166•pjullrich•6d ago•48 comments

Fastmcpp (Fastmcp for C++)

https://github.com/0xeb/fastmcpp
50•0xeb•3d ago•3 comments

PicoIDE – An open IDE/ATAPI drive emulator

https://picoide.com/
171•st_goliath•18h ago•41 comments

A 1961 Relay Computer Running in the Browser

https://minivac.greg.technology/
125•vaibhavsagar•15h ago•32 comments

The fate of "small" open source

https://nolanlawson.com/2025/11/16/the-fate-of-small-open-source/
274•todsacerdoti•22h ago•208 comments

I finally understand Cloudflare Zero Trust tunnels

https://david.coffee/cloudflare-zero-trust-tunnels
285•eustoria•1d ago•89 comments