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.

The Birth and Death of JavaScript (2014)

https://www.destroyallsoftware.com/talks/the-birth-and-death-of-javascript
6•subset•13m ago•0 comments

Free SQL→ER diagram tool, runs in the browser, nothing uploaded

https://sqltoerdiagram.com/
228•robhati•9h ago•42 comments

Honda Civics and the Evil Valet

https://juniperspring.org/posts/honda-evil-valet/
314•librick•12h ago•67 comments

GLM 5.2 Is Out

https://twitter.com/jietang/status/2065784751345287314
650•aloknnikhil•20h ago•368 comments

Windows 1.0 and the WinAPI, 40 Years Later

https://medium.com/@stassaf.uae/windows-1-0-and-the-winapi-40-years-later-abaf64832918
21•jhack•2d ago•9 comments

500-year-old monasteries outperform at digital transformation (U. of Zurich)

https://phys.org/news/2026-05-historic-monasteries-digital-countries.html
46•indynz•2d ago•29 comments

Noise infusion banned from statistical products published by Census Bureau

https://desfontain.es/blog/banning-noise.html
844•nl•22h ago•528 comments

Every Frame Perfect

https://tonsky.me/blog/every-frame-perfect/
771•ravenical•1d ago•245 comments

Don't trust large context windows

https://garrit.xyz/posts/2026-05-06-dont-trust-large-context-windows
151•computersuck•6h ago•107 comments

Treating pancreatic tumours may have revealed cancer's master switch

https://economist.com/science-and-technology/2026/06/12/treating-pancreatic-tumours-may-have-reve...
394•andsoitis•23h ago•135 comments

Tribblix: The retro Illumos distribution

http://tribblix.org/
53•naturalmovement•7h ago•20 comments

Pac-Man, but you're the ghost

https://garrit.xyz/posts/2026-06-13-pac-man-but-you-re-the-ghost
133•mindracer•8h ago•59 comments

FreeOberon – Open-Source, Cross-Platform, Free Pascal/Turbo Pascal-Like Language

https://github.com/kekcleader/FreeOberon
109•peter_d_sherman•2d ago•47 comments

Pyodide 314.0: Python packages can now publish WebAssembly wheels to PyPI

https://blog.pyodide.org/posts/314-release/
143•agriyakhetarpal•4d ago•34 comments

Building a serial and VGA "everything console"

http://oldvcr.blogspot.com/2026/06/building-serial-and-vga-everything.html
39•classichasclass•10h ago•5 comments

Codex for open source

https://openai.com/form/codex-for-oss/
241•EvgeniyZh•2d ago•102 comments

Firewood Splitting Simulator

https://screen.toys/firewood/
8•memalign•4d ago•1 comments

LaserWriter seeds

https://inventingthefuture.ghost.io/laserwriter-seeds/
29•frizlab•3d ago•2 comments

Phoenix LiveView 1.2

https://phoenixframework.org/blog/phoenix-liveview-1-2-released
143•ksec•7h ago•38 comments

A low-carbon computing platform from your retired phones

https://research.google/blog/a-low-carbon-computing-platform-from-your-retired-phones/
303•vikas-sharma•1d ago•160 comments

Beagle: Git, URIs and all the dirty words

https://replicated.wiki/blog/uris.html
21•gritzko•2d ago•7 comments

GameBoy Workboy

https://tcrf.net/Workboy
198•tosh•19h ago•72 comments

Weave: Merging based on language structure and not lines

https://ataraxy-labs.github.io/weave/
50•rohanat•10h ago•34 comments

Amazon CEO's talks with U.S. officials triggered crackdown on Anthropic models

https://www.wsj.com/tech/ai/amazon-ceos-talks-with-u-s-officials-triggered-crackdown-on-anthropic...
721•ls612•19h ago•531 comments

Raress96/Dolby-Atmos-encoder: PoC Dolby Atmos encoder

https://github.com/raress96/dolby-atmos-encoder
16•xbmcuser•2d ago•3 comments

RTX 5080 and RTX 3090 Setup: 80 Tok/s on Qwen 3.6 27B Q8

https://imil.net/blog/posts/2026/rtx-5080-+-rtx-3090-setup-80+-tok-s-on-qwen-3.6-27b-q8/
259•iMil•1d ago•90 comments

Running DOS on Behringers DDX3216 with a DIY x86-Bios from Scratch

https://chrisdevblog.com/2026/06/08/running-dos-on-behringers-ddx3216-using-a-diy-x86-bios/
101•rasz•18h ago•24 comments

The experience of rendering Arabic typography and its technical debt

https://lr0.org/blog/p/arabic/
255•bookofjoe•1d ago•67 comments

AI coding at home without going broke

https://stephen.bochinski.dev/blog/2026/06/13/ai-coding-at-home-without-going-broke/
311•sbochins•20h ago•253 comments

Appreciating Exif

https://brentfitzgerald.com/posts/appreciating-exif/
170•burnto•4d ago•36 comments