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.

I paid people to try and follow my README

https://shkspr.mobi/blog/2026/10/i-paid-people-to-try-and-follow-my-readme/
304•edent•6h ago•155 comments

I'm sorry, but you still have to think

https://itsallaboutthebit.com/i-am-sorry-but-you-still-have-to-think/
132•drogus•3h ago•43 comments

The tilde in your PATH may not be your HOME

https://disconnect3d.pl//2026/10/02/dont-put-tilde-in-your-path/
156•arusekk•6h ago•89 comments

apsw: Another Python SQLite Wrapper

https://github.com/rogerbinns/apsw
12•tosh•1h ago•2 comments

How to Build Wealth as a Career Person

https://asheradeniyi.com/2026/04/10/how-to-build-wealth-as-a-career-person/
25•doppp•2h ago•16 comments

LineageOS 24.0

https://lineageos.org/Changelog-32/
331•timschumi•12h ago•119 comments

How I reverse engineered a commercial spatial audio effect

http://epestr.com/blog/reverse-engineering-a-commercial-spatial-audio-effect/
35•epestr•3h ago•14 comments

Valen's Memory Safety: A New Kind of Borrow Checking

https://verdagon.dev/blog/valen-group-borrowing
90•verdagon•6h ago•41 comments

YouTuber builds 'Flock-like' camera to track police vehicles, gets police visit

https://www.tomshardware.com/tech-industry/cyber-security/canadian-youtuber-builds-flock-like-cam...
22•ljf•41m ago•11 comments

Show HN: BetterWispr – Free, open-source dictation for Mac

https://betterwispr.com/
81•kartik017•6h ago•52 comments

Akhetonics Photonic Computing: 1,000x Faster CPUs

https://medium.com/@timventura/akhetonics-photonic-computing-1-000x-faster-cpus-b9e91c470079
9•peter_d_sherman•3d ago•4 comments

The RAM shortage is bringing back DDR4

https://www.theverge.com/games/1009140/ram-shortage-intel-amd-ddr4-comeback
207•1potato•1d ago•192 comments

We're unlocking the biggest mysteries of the clitoris

https://www.sciencefocus.com/the-human-body/were-finally-unlocking-the-biggest-mysteries-of-the-c...
11•Vaslo•25m ago•1 comments

Nitter: Update Oct 10th seeking funding and legal help

https://nitter.net
350•ForHackernews•7h ago•168 comments

2D Vehicles

https://patkerr.co.uk/2d-vehicles/
587•Michelangelo11•4d ago•112 comments

A Cray-1 supercomputer replica from 30 "obsolete" Mac Minis

https://arstechnica.com/gadgets/2026/10/a-cray-1-supercomputer-replica-from-30-obsolete-mac-minis/
22•pseudolus•1d ago•8 comments

3rd Yandex Cloud Data Center Was Hit

https://status.yandex.cloud/en/incidents/2136
439•defly•10h ago•529 comments

Weave (YC W25) is hiring ML, AI, product, & design engineers

https://jobs.ashbyhq.com/weave-os
1•adchurch•6h ago

A city-building game in which the city would prefer you didn't

https://housing.over.pizza/
492•JumpCrisscross•21h ago•163 comments

Build your own decision model

https://nishtahir.com/build-your-own-decision-model/
431•softwaredoug•19h ago•97 comments

IRCv3

https://ircv3.net/
253•basilikum•8h ago•231 comments

The Lightbulb Computer

https://lightbulbcomputer.com/
555•oskarth•1d ago•93 comments

Bot traffic from Yandex

https://radar.cloudflare.com/bots/as13238?dateRange=7d
541•walrus01•7h ago•204 comments

Documents add to evidence in climate deception case against ExxonMobil

https://insideclimatenews.org/news/07102026/exxonmobil-climate-deception-new-evidence/
339•gumby•3h ago•174 comments

Plumbers, chains, and famous painters: The history of the pipe operator in R

http://adolfoalvarez.cl/blog/2021-09-16-plumbers-chains-and-famous-painters-the-history-of-the-pi...
35•sinnsro•2d ago•2 comments

The Wild West of polyglot docs sites

https://technicalwriting.dev/blog/2026/10/polyglot/index.html
10•zdw•2d ago•1 comments

Rat's Register Allocator

https://hexrat.cc/pages/blog/2026_10_07
50•mpweiher•1d ago•2 comments

How big is a Git commit?

https://ratfactor.com/cards/git-commit-size
72•theanonymousone•2d ago•29 comments

PSPi 6 – Raspberry Pi in a PSP

https://github.com/othermod/PSPi-Version-6
125•therepanic•17h ago•12 comments

Retrofitting language models to operate over bytes

https://www.nature.com/articles/s41586-026-11111-4
100•theanonymousone•3d ago•20 comments