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.

Flux 3

https://bfl.ai/blog/flux-3
208•ThouYS•2h ago•49 comments

The PImpl idiom and the C++26 std:indirect type

https://mariusbancila.ro/blog/2026/07/23/the-pimpl-idiom-and-the-cpp26-stdindirect-type/
38•signa11•2h ago•35 comments

Writing by hand is good for your brain

https://nealstephenson.substack.com/p/writing-by-hand-is-good-for-your
1293•dwwoelfel•18h ago•583 comments

Startup founders urge U.S. government not to shut off Chinese open weight AI

https://www.politico.com/news/2026/07/22/startup-founders-urge-trump-not-to-shut-off-chinese-open...
921•theanonymousone•17h ago•764 comments

Show HN: Echo – Fable-level results at 1/3 the cost using open-weight models

378•adam_rida•13h ago•179 comments

The Beam Engine

https://glinscott.github.io/beam-engine/
370•glinscott•1d ago•74 comments

Claude Cookbook

https://platform.claude.com/cookbook/
31•saikatsg•4h ago•3 comments

What happened to TheNumbers.com

https://stephenfollows.com/p/what-just-happened-to-thenumberscom-should-worry-us-all
368•nickthegreek•16h ago•166 comments

Why Software Factories Fail (or: harness engineering is not enough)

https://github.com/humanlayer/advanced-context-engineering-for-coding-agents/blob/main/wsff.md
308•dhorthy•17h ago•224 comments

What else do people draw on gradient.horse?

https://rybakov.com/blog/what_else_do_people_draw_on_gradient-copy.horse/
130•spython•5d ago•22 comments

Learn OpenGL, extensive tutorial resource for learning Modern OpenGL

https://learnopengl.com/
238•ibobev•18h ago•119 comments

Quickly rewrite Git repository history

https://github.com/newren/git-filter-repo
39•modinfo•3d ago•1 comments

I regret migrating to Codeberg

https://xn--gckvb8fzb.com/i-regret-migrating-to-codeberg/
283•boramalper•19h ago•177 comments

DARPA, U.S. Air Force fly AI-controlled F-16

https://www.darpa.mil/news/2026/darpa-us-air-force-fly-ai-controlled-f-16
240•r2sk5t•19h ago•268 comments

Software rendering in 500 lines of bare C++

https://haqr.eu/tinyrenderer/
281•mpweiher•18h ago•63 comments

Why Sony can't bring back its classic Walkman models

https://obsoletesony.substack.com/p/why-sony-cant-bring-back-classic-walkman
115•speckx•15h ago•124 comments

98.css

https://jdan.github.io/98.css/#status-bar
467•lopespm•10h ago•108 comments

Projects every RC live races and results

https://rc-replay.dev/lr/vmrc/r/6912053
8•apokly•3d ago•0 comments

Show HN: Palmier Pro – Open-source macOS video editor built for AI

https://github.com/palmier-io/palmier-pro
152•harrisontin•18h ago•25 comments

Building on ATProto

https://lukekanies.com/writing/building-on-atproto/
157•speckx•14h ago•80 comments

Astronomers may have found the first exomoon

https://www.eso.org/public/news/eso2610/
219•MarcoDewey•19h ago•82 comments

Fields Medals 2026

https://www.mathunion.org/imu-awards/fields-medal/fields-medals-2026
177•nill0•18h ago•90 comments

OpenAI’s accidental attack against Hugging Face is science fiction that happened

https://simonwillison.net/2026/Jul/22/openai-cyberattack/
512•abhisek•1d ago•394 comments

Modula-3 History Collection on Computer History Museum

https://softwarepreservation.computerhistory.org/modula3/
24•pjmlp•3d ago•4 comments

Launch HN: Screenpipe (YC S26) – Record how you work and turn that into agents

74•louis030195•16h ago•53 comments

The arguments against open source AI are bad

https://tombedor.dev/arguments-against-open-source-ai-are-very-bad/
270•jjfoooo4•16h ago•188 comments

A solid-state “atomic channel” for separating rare earth elements

https://pme.uchicago.edu/news-events/news/cleaner-route-purifying-rare-earth-elements
90•MarcoDewey•14h ago•25 comments

Freeze-Casting

https://en.wikipedia.org/wiki/Freeze-casting
25•soupspaces•4d ago•5 comments

Mourning Dan Williams

https://lwn.net/Articles/1084545/
71•speckx•13h ago•1 comments

The Visual 6502

http://visual6502.org/JSSim/index.html
94•infiniteregrets•9h ago•22 comments