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

Comments

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

How I use Claude Code: Separation of planning and execution

https://boristane.com/blog/how-i-use-claude-code/
183•vinhnx•3h ago•104 comments

Palantir's secret weapon isn't AI – it's Ontology. An open-source deep dive

https://github.com/Leading-AI-IO/palantir-ontology-strategy
25•leading-AI•1h ago•14 comments

Show HN: Llama 3.1 70B on a single RTX 3090 via NVMe-to-GPU bypassing the CPU

https://github.com/xaskasdf/ntransformer
123•xaskasdf•6h ago•29 comments

A Botnet Accidentally Destroyed I2P

https://www.sambent.com/a-botnet-accidentally-destroyed-i2p-the-full-story/
25•Cider9986•2h ago•9 comments

Evidence of the bouba-kiki effect in naïve baby chicks

https://www.science.org/doi/10.1126/science.adq7188
83•suddenlybananas•5h ago•23 comments

Japanese Woodblock Print Search

https://ukiyo-e.org/
4•curmudgeon22•13m ago•0 comments

Parse, Don't Validate and Type-Driven Design in Rust

https://www.harudagondi.space/blog/parse-dont-validate-and-type-driven-design-in-rust/
135•todsacerdoti•7h ago•38 comments

How far back in time can you understand English?

https://www.deadlanguagesociety.com/p/how-far-back-in-time-understand-english
389•spzb•3d ago•229 comments

Scientists discover recent tectonic activity on the moon

https://phys.org/news/2026-02-scientists-tectonic-moon.html
17•bookmtn•4d ago•0 comments

zclaw: personal AI assistant in under 888 KB, running on an ESP32

https://github.com/tnm/zclaw
117•tosh•14h ago•61 comments

The Internet Is Becoming a Dark Forest – and AI Is the Hunter

https://opennhp.org/blog/the-internet-is-becoming-a-dark-forest.html
9•windcbf•2h ago•7 comments

CXMT has been offering DDR4 chips at about half the prevailing market rate

https://www.koreaherald.com/article/10679206
165•phront•12h ago•146 comments

Claws are now a new layer on top of LLM agents

https://twitter.com/karpathy/status/2024987174077432126
212•Cyphase•1d ago•661 comments

EDuke32 – Duke Nukem 3D (Open-Source)

https://www.eduke32.com/
157•reconnecting•7h ago•59 comments

Finding forall-exists Hyperbugs using Symbolic Execution

https://dl.acm.org/doi/full/10.1145/3689761
21•todsacerdoti•5d ago•0 comments

Toyota Mirai hydrogen car depreciation: 65% value loss in a year

https://carbuzz.com/toyota-mirai-massive-depreciation-one-year/
105•iancmceachern•9h ago•248 comments

Inputlag.science – Repository of knowledge about input lag in gaming

https://inputlag.science
71•akyuu•7h ago•12 comments

Canvas_ity: A tiny, single-header <canvas>-like 2D rasterizer for C++

https://github.com/a-e-k/canvas_ity
65•PaulHoule•8h ago•23 comments

Acme Weather

https://acmeweather.com/blog/introducing-acme-weather
209•cryptoz•20h ago•126 comments

What not to write on your security clearance form (1988)

https://milk.com/wall-o-shame/security_clearance.html
395•wizardforhire•10h ago•177 comments

Two Bits Are Better Than One: making bloom filters 2x more accurate

https://floedb.ai/blog/two-bits-are-better-than-one-making-bloom-filters-2x-more-accurate
11•matheusalmeida•4d ago•0 comments

Forward propagation of errors through time

https://nicolaszucchet.github.io/Forward-propagation-errors-through-time/
9•iNic•2d ago•0 comments

I verified my LinkedIn identity. Here's what I handed over

https://thelocalstack.eu/posts/linkedin-identity-verification-privacy/
1188•ColinWright•20h ago•416 comments

Be wary of Bluesky

https://kevinak.se/blog/be-wary-of-bluesky
257•kevinak•1d ago•177 comments

Permacomputing

https://wiki.xxiivv.com/site/permacomputing.html
109•tosh•4d ago•27 comments

Personal Statement of a CIA Analyst

https://antipolygraph.org/statements/statement-038.shtml
183•grubbs•9h ago•110 comments

Uncovering insiders and alpha on Polymarket with AI

https://twitter.com/peterjliu/status/2024901585806225723
133•somerandomness•1d ago•126 comments

A16z partner says that the theory that we’ll vibe code everything is wrong

https://www.aol.com/articles/a16z-partner-says-theory-well-050150534.html
91•paulpauper•1d ago•131 comments

I Don't Like Magic

https://adactio.com/journal/22399
118•edent•3d ago•99 comments

Keep Android Open

https://f-droid.org/2026/02/20/twif.html
2002•LorenDB•1d ago•693 comments