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

Comments

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

Rare concert recordings are landing on the Internet Archive

https://techcrunch.com/2026/04/13/thousands-of-rare-concert-recordings-are-landing-on-the-interne...
105•jrm-veris•2h ago•41 comments

What is jj and why should I care?

https://steveklabnik.github.io/jujutsu-tutorial/introduction/what-is-jj-and-why-should-i-care.html
314•tigerlily•5h ago•249 comments

DaVinci Resolve – Photo

https://www.blackmagicdesign.com/products/davinciresolve/photo
853•thebiblelover7•13h ago•222 comments

A new spam policy for “back button hijacking”

https://developers.google.com/search/blog/2026/04/back-button-hijacking
619•zdw•12h ago•360 comments

AI Will Never Be Ethical or Safe

https://meiert.com/blog/ai-ethics-and-safety/
7•caisah•16m ago•0 comments

NimConf 2026: Dates Announced, Registrations Open

https://nim-lang.org/blog/2026/04/07/nimconf-2026.html
71•moigagoo•4h ago•13 comments

Show HN: Kontext CLI – Credential broker for AI coding agents in Go

https://github.com/kontext-dev/kontext-cli
11•mc-serious•2h ago•0 comments

Backblaze has stopped backing up your data

https://rareese.com/posts/backblaze/
553•rrreese•7h ago•342 comments

The acyclic e-graph: Cranelift's mid-end optimizer

https://cfallin.org/blog/2026/04/09/aegraph/
30•tekknolagi•4d ago•9 comments

Introspective Diffusion Language Models

https://introspective-diffusion.github.io/
143•zagwdt•7h ago•34 comments

Nucleus Nouns

https://ben-mini.com/2026/nucleus-nouns
8•bewal416•4d ago•1 comments

Franklin's bad ads for Apple ][ clones and the beloved impersonator they depict

https://buttondown.com/suchbadtechads/archive/franklin-ace-1000/
84•rfarley04•3d ago•43 comments

The M×N problem of tool calling and open-source models

https://www.thetypicalset.com/blog/grammar-parser-maintenance-contract
65•remilouf•5d ago•19 comments

The AI School Bus Camera Company Blanketing America in Tickets

https://www.bloomberg.com/news/features/2026-04-14/buspatrol-school-bus-traffic-tickets-have-limi...
26•jimt1234•40m ago•34 comments

Distributed DuckDB Instance

https://github.com/citguru/openduck
115•citguru•9h ago•27 comments

Ransomware Is Growing Three Times Faster Than the Spending Meant to Stop It

https://ciphercue.com/blog/ransomware-claims-grew-faster-than-security-spend-2025
73•adulion•6h ago•64 comments

Lean proved this program correct; then I found a bug

https://kirancodes.me/posts/log-who-watches-the-watchers.html
326•bumbledraven•15h ago•154 comments

The exponential curve behind open source backlogs

https://armanckeser.com/writing/jellyfin-flow
35•armanckeser•4h ago•24 comments

Show HN: Run GUIs as Scripts

https://github.com/skinnyjames/hokusai-pocket
9•zero-st4rs•4d ago•2 comments

Multi-Agentic Software Development Is a Distributed Systems Problem

https://kirancodes.me/posts/log-distributed-llms.html
83•tie-in•10h ago•37 comments

Someone bought 30 WordPress plugins and planted a backdoor in all of them

https://anchor.host/someone-bought-30-wordpress-plugins-and-planted-a-backdoor-in-all-of-them/
1085•speckx•21h ago•305 comments

WiiFin – Jellyfin Client for Nintendo Wii

https://github.com/fabienmillet/WiiFin
209•throwawayk7h•16h ago•95 comments

MOS tech 6502 8-bit microprocessor in pure SQL powered by Postgres

https://github.com/lasect/pg_6502
57•adunk•10h ago•8 comments

The Future of Everything Is Lies, I Guess: Work

https://aphyr.com/posts/418-the-future-of-everything-is-lies-i-guess-work
37•aphyr•46m ago•17 comments

A soft robot has no problem moving with no motor and no gears

https://engineering.princeton.edu/news/2026/04/08/soft-robot-has-no-problem-moving-no-motor-and-n...
62•hhs•4d ago•17 comments

Lumina – a statically typed web-native language for JavaScript and WASM

https://github.com/nyigoro/lumina-lang
42•light_ideas•4d ago•17 comments

The Great Majority: Body Snatching and Burial Reform in 19th-Century Britain

https://publicdomainreview.org/essay/the-great-majority/
15•apollinaire•3d ago•1 comments

GitHub Stacked PRs

https://github.github.com/gh-stack/
824•ezekg•19h ago•454 comments

Write less code, be more responsible

https://blog.orhun.dev/code-responsibly/
139•orhunp_•3d ago•86 comments

Design and implementation of DuckDB internals

https://duckdb.org/library/design-and-implementation-of-duckdb-internals/
159•mpweiher•4d ago•11 comments