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.

Android now stops you sharing your location in photos

https://shkspr.mobi/blog/2026/04/android-now-stops-you-sharing-your-location-in-photos/
148•edent•2h ago•87 comments

AI could be the end of the digital wave, not the next big thing

https://thenextwavefutures.wordpress.com/2026/04/07/ai-end-digital-wave-technology-innovation-perez/
90•surprisetalk•1h ago•63 comments

They See Your Photos

https://theyseeyourphotos.com/
48•cyberlurker•33m ago•29 comments

I went to America's worst national parks so you don't have to

https://substack.com/home/post/p-193626949
122•surprisetalk•1h ago•50 comments

All elementary functions from a single binary operator

https://arxiv.org/abs/2603.21852
595•pizza•12h ago•159 comments

Servo is now available on crates.io

https://servo.org/blog/2026/04/13/servo-0.1.0-release/
23•ffin•1h ago•4 comments

The economics of software teams: Why most engineering orgs are flying blind

https://www.viktorcessan.com/the-economics-of-software-teams/
262•kiyanwang•8h ago•139 comments

US appeals court declares 158-year-old home distilling ban unconstitutional

https://nypost.com/2026/04/11/us-news/us-appeals-court-declares-158-year-old-home-distilling-ban-...
17•t-3•23m ago•1 comments

Michigan 'digital age' bills pulled after privacy concerns raised

https://www.thecentersquare.com/michigan/article_7ca4e268-4a68-42fb-9042-f9d8604ebd7f.html
45•iamnothere•1h ago•23 comments

Point Cloud Allemansrätten

https://digitalflapjack.com/weeknotes/point-cloud-allemansr%C3%A4tten/
26•ColinWright•3h ago•1 comments

Taking on CUDA with ROCm: 'One Step After Another'

https://www.eetimes.com/taking-on-cuda-with-rocm-one-step-after-another/
216•mindcrime•15h ago•161 comments

DIY Soft Drinks

https://blinry.org/diy-soft-drinks/
559•_Microft•21h ago•166 comments

Bring Back Idiomatic Design (2023)

https://essays.johnloeber.com/p/4-bring-back-idiomatic-design
600•phil294•1d ago•344 comments

Show HN: boringBar – a taskbar-style dock replacement for macOS

https://boringbar.app/
424•a-ve•20h ago•239 comments

Show HN: I built a social media management tool in 3 weeks with Claude and Codex

https://github.com/brightbeanxyz/brightbean-studio
112•JanSchu•4h ago•76 comments

Most people can't juggle one ball

https://www.lesswrong.com/posts/jTGbKKGqs5EdyYoRc/most-people-can-t-juggle-one-ball
422•surprisetalk•4d ago•140 comments

Ask HN: What Are You Working On? (April 2026)

264•david927•21h ago•857 comments

A perfectable programming language

https://alok.github.io/lean-pages/perfectable-lean/
167•yuppiemephisto•16h ago•66 comments

I gave every train in New York an instrument

https://www.trainjazz.com/
329•joshuawolk•2d ago•65 comments

Optimization of 32-bit Unsigned Division by Constants on 64-bit Targets

https://arxiv.org/abs/2604.07902
99•mpweiher•1d ago•12 comments

Tell HN: Docker pull fails in Spain due to football Cloudflare block

1018•littlecranky67•1d ago•374 comments

We have a 99% email reputation, but Gmail disagrees

https://blogfontawesome.wpcomstaging.com/we-have-a-99-email-reputation-gmail-disagrees/
296•em-bee•1d ago•263 comments

Show HN: Oberon System 3 runs natively on Raspberry Pi 3 (with ready SD card)

https://github.com/rochus-keller/OberonSystem3Native/releases
211•Rochus•1d ago•61 comments

I ran Gemma 4 as a local model in Codex CLI

https://blog.danielvaughan.com/i-ran-gemma-4-as-a-local-model-in-codex-cli-7fda754dc0d4
132•dvaughan•17h ago•58 comments

Is math big or small?

https://chessapig.github.io/talks/Big-Small
61•robinhouston•1d ago•24 comments

Apple's accidental moat: How the "AI Loser" may end up winning

https://adlrocha.substack.com/p/adlrocha-how-the-ai-loser-may-end
299•walterbell•11h ago•272 comments

Exploiting the most prominent AI agent benchmarks

https://rdi.berkeley.edu/blog/trustworthy-benchmarks-cont/
547•Anon84•1d ago•134 comments

Seven countries now generate nearly all their electricity from renewables (2024)

https://www.the-independent.com/tech/renewable-energy-solar-nepal-bhutan-iceland-b2533699.html
615•mpweiher•1d ago•410 comments

JVM Options Explorer

https://chriswhocodes.com/vm-options-explorer.html
208•0x54MUR41•1d ago•94 comments

Phyphox – Physical Experiments Using a Smartphone

https://phyphox.org/
239•_Microft•1d ago•35 comments