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.

Mechanical Watch (2022)

https://ciechanow.ski/mechanical-watch/
171•razin•1h ago•25 comments

The time the x86 emulator team found code so bad they fixed it during emulation

https://devblogs.microsoft.com/oldnewthing/20260615-00/?p=112419
353•paulmooreparks•8h ago•108 comments

John Carmack on Fabrice Bellard

https://twitter.com/ID_AA_Carmack/status/2064095424420487226
454•apitman•8h ago•239 comments

Correlated randomness in Slay the Spire 2

https://tck.mn/blog/correlated-randomness-sts2/
48•rdmuser•3h ago•20 comments

A backdoor in a LinkedIn job offer

https://roman.pt/posts/linkedin-backdoor/
1327•lwhsiao•17h ago•249 comments

Getting Creative with Perlin Noise Fields

https://sighack.com/post/getting-creative-with-perlin-noise-fields
69•0x000xca0xfe•2d ago•14 comments

Trinket.io shutting down, so we saved it and hosted it a trinket.strivemath.org

https://trinket.strivemath.org/
58•apulkit6•3h ago•7 comments

Iroh 1.0

https://www.iroh.computer/blog/v1
1267•chadfowler•22h ago•387 comments

Banned Book Library in a Wi-Fi Smart Light Bulb

https://www.richardosgood.com/posts/banned-book-library/
460•sohkamyung•14h ago•251 comments

Feds freaked over Fable 5 after simple 'fix this code' prompt, not jailbreak

https://www.theregister.com/security/2026/06/15/feds-freaked-over-fable-5-after-simple-fix-this-c...
194•_tk_•3h ago•105 comments

Ask HN: Has anyone replaced Claude/GPT with a local model for daily coding?

1110•cloudking•22h ago•478 comments

SpaceX Is Buying Cursor

https://www.bbc.com/news/articles/cvgd5g7d7gyo
97•jrm-veris•44m ago•97 comments

Understanding the rationale behind a rule when trying to circumvent it

https://devblogs.microsoft.com/oldnewthing/20260611-00/?p=112415
58•tosh•5h ago•16 comments

TinyWind: A pixel pirate sailing game with real wind physics (380k+ kms sailed)

https://tinywind.io
903•tinywind•21h ago•162 comments

Show HN: Garden of Flowers – an archive of pictorial typography before ASCII art

https://garden-of-flowers.heikkilotvonen.com/
99•california-og•8h ago•14 comments

I Love the Computer

https://michaelenger.com/blog/i-love-the-computer/
260•speckx•17h ago•149 comments

Color Photos of Stalin-Era Soviet Union Taken by a US Diplomat

https://rarehistoricalphotos.com/stalin-era-soviet-union-pictures-martin-manhoff/
56•Cider9986•2d ago•8 comments

Unicorn – The Ultimate CPU Emulator

https://www.unicorn-engine.org/
4•tosh•2h ago•0 comments

I hacked into the worst e-bike and fixed it [video]

https://www.youtube.com/watch?v=hPrtVGimBYs
121•alexis-d•5d ago•55 comments

Hetzner Price Adjustment

https://docs.hetzner.com/general/infrastructure-and-availability/price-adjustment/#cloud-servers
498•tuhtah•23h ago•679 comments

Peopleless economy? Not technically impossible

https://gmalandrakis.com/writings/ad-economicum.html
228•l0new0lf-G•16h ago•416 comments

Cohere's First Model for Developers

https://cohere.com/blog/north-mini-code
117•hmokiguess•5d ago•27 comments

My Homelab AI Dev Platform

https://rsgm.dev/post/ai-dev-platform/
332•rsgm•22h ago•54 comments

Why I email complete strangers

https://www.goodinternetmagazine.com/why-i-email-complete-strangers/
176•karakoram•15h ago•79 comments

Hans Schulz – The father of the VEF Minox lens?

https://moments-of-now.com/hans-schulz-the-father-of-the-vef-minox-riga-lens/
7•throwaway81523•2d ago•1 comments

Fox to buy Roku

https://www.wsj.com/business/deals/fox-roku-deal-f6e564f9
334•thm•1d ago•408 comments

SpaceX to buy Cursor AI coding agent operator Anysphere for $60B

https://www.reuters.com/legal/transactional/spacex-buy-anysphere-60-billion-2026-06-16/
136•itsmarcelg•2h ago•88 comments

What job interviews taught me about Kubernetes

https://notnotp.com/notes/what-job-interviews-taught-me-about-kubernetes/
214•chmaynard•17h ago•166 comments

Commodore Releases Flip Phone

https://commodore.net/why-a-flip-phone/
121•bartekrutkowski•4h ago•71 comments

Copper transport drug restores memory and clears toxic Alzheimer's proteins

https://www.monash.edu/news/articles/copper-drug-restores-memory-and-clears-toxic-alzheimers-prot...
331•bookofjoe•22h ago•116 comments