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.

Linux Kernel Explorer

https://reverser.dev/linux-kernel-explorer
107•tanelpoder•3h ago•20 comments

Penpot: The Open-Source Figma

https://github.com/penpot/penpot
320•selvan•7h ago•50 comments

Ray Marching Soft Shadows in 2D

https://www.rykap.com/2020/09/23/distance-fields/
49•memalign•2h ago•5 comments

Interactive λ-Reduction

https://deltanets.org/
28•jy14898•2d ago•9 comments

DIY NAS: 2026 Edition

https://blog.briancmoses.com/2025/11/diy-nas-2026-edition.html
188•sashk•7h ago•68 comments

Voyager 1 is about to reach one light-day from Earth

https://scienceclock.com/voyager-1-is-about-to-reach-one-light-day-from-earth/
926•ashishgupta2209•20h ago•314 comments

Music eases surgery and speeds recovery, study finds

https://www.bbc.com/news/articles/c231dv9zpz3o
73•1659447091•5h ago•18 comments

Willis Whitfield: A simple man with a simple solution that changed the world

https://www.sandia.gov/labnews/2024/04/04/willis-whitfield-a-simple-man-with-a-simple-solution-th...
70•rbanffy•2d ago•20 comments

G0-G3 corners, visualised: learn what "Apple corners" are

https://www.printables.com/model/1490911-g0-g3-corners-visualised-learn-what-apple-corners
40•dgroshev•3d ago•11 comments

S&box is now an open source game engine

https://sbox.game/news/update-25-11-26
318•MaximilianEmel•14h ago•102 comments

Coq: The World's Best Macro Assembler? [pdf] [2013]

https://nickbenton.name/coqasm.pdf
70•addaon•5h ago•27 comments

New research highlights a shortage of male mentors for boys and young men

https://www.psypost.org/new-research-highlights-a-shortage-of-male-mentors-for-boys-and-young-men/
22•ashishgupta2209•55m ago•12 comments

Principles of Vasocomputation

https://opentheory.net/2023/07/principles-of-vasocomputation-a-unification-of-buddhist-phenomenol...
23•eatitraw•4h ago•5 comments

Gemini CLI Tips and Tricks for Agentic Coding

https://github.com/addyosmani/gemini-cli-tips
279•ayoisaiah•16h ago•94 comments

Migrating the main Zig repository from GitHub to Codeberg

https://ziglang.org/news/migrating-from-github-to-codeberg/
614•todsacerdoti•8h ago•507 comments

Running Unsupported iOS on Deprecated Devices

https://nyansatan.github.io/run-unsupported-ios/
152•OuterVale•11h ago•55 comments

Functional Data Structures and Algorithms: a Proof Assistant Approach

https://fdsa-book.net/
54•SchwKatze•8h ago•8 comments

Can you take an ox to Oxford?

https://alexwlchan.net/2025/ox-in-oxford/
12•surprisetalk•5d ago•3 comments

Last Issue of "ECMAScript News"

https://ecmascript.news/archive/es-next-news-2025-11-26.html
17•Klaster_1•3h ago•3 comments

Show HN: Era – Open-source local sandbox for AI agents

https://github.com/BinSquare/ERA
20•gregTurri•4h ago•9 comments

How/why to sweep async tasks under a Postgres table

https://taylor.town/pg-task
51•ostler•5d ago•17 comments

A Fast 64-Bit Date Algorithm (30–40% faster by counting dates backwards)

https://www.benjoffe.com/fast-date-64
330•benjoffe•4d ago•75 comments

Fara-7B: An efficient agentic model for computer use

https://github.com/microsoft/fara
133•maxloh•15h ago•44 comments

C100 Developer Terminal

https://caligra.com/
73•matthewsinclair•10h ago•79 comments

The EU made Apple adopt new Wi-Fi standards, and now Android can support AirDrop

https://arstechnica.com/gadgets/2025/11/the-eu-made-apple-adopt-new-wi-fi-standards-and-now-andro...
468•cyclecount•12h ago•216 comments

$96M AUD revamp of Bom website bombs out on launch

https://www.bbc.com/news/articles/c2k4dy15nqqo
15•sam-cop-vimes•5h ago•8 comments

Bring bathroom doors back to hotels

https://bringbackdoors.com/
659•bariumbitmap•11h ago•508 comments

Bonsai_term: A library for building dynamic terminal apps by Jane Street

https://github.com/janestreet/bonsai_term
31•azhenley•8h ago•9 comments

A woman on a mission to photograph every species of hummingbird

https://www.audubon.org/magazine/meet-woman-mission-photograph-every-species-of-hummingbird-world
132•zeech•4d ago•27 comments

DNS Firewalling with MISP and Technitium DNS Server

https://zaferbalkan.com/technitium-misp/
7•feldrim•2h ago•5 comments