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

Comments

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

Linux Sandboxes and Fil-C

https://fil-c.org/seccomp
109•pizlonator•3h ago•25 comments

Recovering Anthony Bourdain's (really) lost Li.st's

https://sandyuraz.com/blogs/bourdain/
125•thecsw•5h ago•41 comments

Closures as Win32 Window Procedures

https://nullprogram.com/blog/2025/12/12/
40•ibobev•3h ago•3 comments

An Implementation of J

https://www.jsoftware.com/ioj/ioj.htm
11•ofalkaed•2h ago•0 comments

I tried Gleam for Advent of Code

https://blog.tymscar.com/posts/gleamaoc2025/
241•tymscar•9h ago•134 comments

I fed 24 years of my blog posts to a Markov model

https://susam.net/fed-24-years-of-posts-to-markov-model.html
104•zdw•6h ago•38 comments

VPN location claims don't match real traffic exits

https://ipinfo.io/blog/vpn-location-mismatch-report
259•mmaia•6h ago•150 comments

Cat Gap

https://en.wikipedia.org/wiki/Cat_gap
47•Petiver•3d ago•5 comments

Using E-Ink tablet as monitor for Linux

https://alavi.me/blog/e-ink-tablet-as-monitor-linux/
19•yolkedgeek•4d ago•5 comments

The Rise of Computer Games, Part I: Adventure

https://technicshistory.com/2025/12/13/the-rise-of-computer-games-part-i-adventure/
53•cfmcdonald•6h ago•15 comments

Why Twilio Segment moved from microservices back to a monolith

https://www.twilio.com/en-us/blog/developers/best-practices/goodbye-microservices
177•birdculture•6h ago•136 comments

llamafile: Distribute and Run LLMs with a Single File

https://github.com/mozilla-ai/llamafile
29•stefankuehnel•7h ago•2 comments

Useful patterns for building HTML tools

https://simonwillison.net/2025/Dec/10/html-tools/
251•simonw•3d ago•72 comments

Ask HN: How can I get better at using AI for programming?

229•lemonlime227•11h ago•267 comments

Awesome-Jj: Jujutsu Things

https://github.com/Necior/awesome-jj
6•n3t•1h ago•0 comments

Cryptids

https://wiki.bbchallenge.org/wiki/Cryptids
93•frozenseven•1w ago•14 comments

Go Proposal: Secret Mode

https://antonz.org/accepted/runtime-secret/
167•enz•4d ago•73 comments

Some surprising things about DuckDuckGo

https://gabrielweinberg.com/p/some-surprising-things-about-duckduckgo
67•ArmageddonIt•4h ago•45 comments

A Giant Ball Will Help This Man Survive a Year on an Iceberg

https://www.outsideonline.com/outdoor-adventure/exploration-survival/how-giant-ball-will-help-man...
43•areoform•11h ago•35 comments

From Azure Functions to FreeBSD

https://jmmv.dev/2025/12/from-azure-functions-to-freebsd.html
70•todsacerdoti•5d ago•7 comments

Flat-pack washing machine spins a fairer future

https://www.positive.news/society/flat-pack-washing-machine-spins-a-fairer-future/
58•ohjeez•4h ago•27 comments

EasyPost (YC S13) Is Hiring

https://www.easypost.com/careers
1•jstreebin•9h ago

Want to sway an election? Here’s how much fake online accounts cost

https://www.science.org/content/article/want-sway-election-here-s-how-much-fake-online-accounts-cost
143•rbanffy•5h ago•94 comments

Free Software Awards Winners Announced: Andy Wingo, Alx Sa, Govdirectory

https://www.fsf.org/news/2024-free-software-awards-winners
11•pseudolus•1h ago•0 comments

What is the nicest thing a stranger has ever done for you?

https://louplummer.lol/nice-stranger/
304•speckx•2d ago•236 comments

Using Python for Scripting

https://hypirion.com/musings/use-python-for-scripting
98•birdculture•5d ago•78 comments

Photographer built a medium-format rangefinder

https://petapixel.com/2025/12/06/this-photographer-built-an-awesome-medium-format-rangefinder-and...
165•shinryuu•1w ago•41 comments

Researchers seeking better measures of cognitive fatigue

https://www.nature.com/articles/d41586-025-03974-w
108•bikenaga•3d ago•31 comments

Are we stuck with the same Desktop UX forever? [video]

https://www.youtube.com/watch?v=1fZTOjd_bOQ
121•joelkesler•8h ago•128 comments

TigerBeetle as a File Storage

https://aivarsk.com/2025/12/07/tigerbeetle-blob-storage/
24•aivarsk•6d ago•2 comments