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

Comments

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

Total monthly number of StackOverflow questions over time

https://data.stackexchange.com/stackoverflow/query/1926661#graph
539•maartin0•3h ago•317 comments

The suck is why we're here

https://nik.art/the-suck-is-why-were-here/
84•herbertl•2h ago•25 comments

Swift on Android: Full Native App Development Now Possible

https://docs.swifdroid.com/app/
91•mihael•2h ago•47 comments

The Most Popular Blogs of Hacker News in 2025

https://refactoringenglish.com/blog/2025-hn-top-5/
421•mtlynch•9h ago•89 comments

Ed25519-CLI – command-line interface for the Ed25519 signature system

https://lib25519.cr.yp.to/ed25519-cli.html
59•INGELRII•6d ago•16 comments

The Riven Diffs – Seeing Riven (1997) Differently

https://glthr.com/the-riven-diffs-1
46•glth•3h ago•4 comments

MyTorch – Minimalist autograd in 450 lines of Python

https://github.com/obround/mytorch
6•iguana2000•54m ago•0 comments

Take One Small Step

https://thinkhuman.com/take-one-small-step/
41•jamesgill•4h ago•12 comments

The C3 Programming Language

https://c3-lang.org
293•y1n0•9h ago•176 comments

Torch.ts – building PyTorch in TypeScript from scratch to learn

https://github.com/13point5/torch.ts
14•13point5•3d ago•2 comments

Determining Current Arm Cortex-M Security State with GDB

https://danielmangum.com/posts/arm-cortex-m-security-state-gdb/
19•hasheddan•6d ago•0 comments

China DRAM Maker CXMT Targets $4.2B IPO as It Takes on Samsung, SK Hynix, Micron

https://www.ic-pcb.com/chinas-leading-dram-maker-cxmt-targets-42-billion-ipo-as-it-takes-on-samsu...
90•walterbell•3h ago•26 comments

Scaling Latent Reasoning via Looped Language Models

https://arxiv.org/abs/2510.25741
38•remexre•4h ago•6 comments

Xr0 verifier, guarantee the safety of C programs at compile time

https://xr0.dev
57•Alifatisk•8h ago•14 comments

The Great Gatsby is the most misunderstood novel

https://www.bbc.com/culture/article/20210209-the-worlds-most-misunderstood-novel
4•1659447091•1h ago•1 comments

Slop Is Slop

https://daringfireball.net/2025/12/slop_is_slop
31•JumpCrisscross•5d ago•13 comments

Exploring Dithering on Spectra 6-color E-Ink Displays

https://myembeddedstuff.com/e-ink-spectra-6-color
78•edent•4d ago•2 comments

Publish on your own site, syndicate elsewhere

https://indieweb.org/POSSE#
1005•47thpresident•1d ago•234 comments

Show HN: Offline tiles and routing and geocoding in one Docker Compose stack

https://www.corviont.com/
79•packet_mover•10h ago•23 comments

Daft Punk Easter Egg in the BPM Tempo of Harder, Better, Faster, Stronger?

https://www.madebywindmill.com/tempi/blog/hbfs-bpm/
751•simonw•1d ago•121 comments

Experiments with Ableton-MCP

https://jhurliman.org/post/804323197731373056/experiments-with-ableton-mcp-dec-2025
70•jhurliman•4d ago•10 comments

Trump says Venezuela’s Maduro captured after strikes

https://www.reuters.com/world/americas/loud-noises-heard-venezuela-capital-southern-area-without-...
1563•jumpocelot•19h ago•3735 comments

Sirius DB

https://www.sirius-db.com/
102•manoji•3d ago•15 comments

Recursive Language Models

https://arxiv.org/abs/2512.24601
118•schmuhblaster•14h ago•20 comments

Pickle 1 AR Glasses (YC W25) May Be Fraudulent

https://twitter.com/thedowd/status/2007337800430198913
50•tragiclos•1h ago•6 comments

As deep-sea mining race ramps up, mission will assess whether ecosystems recover

https://www.science.org/content/article/deep-sea-mining-race-ramps-mission-will-assess-whether-ec...
56•rbanffy•7h ago•46 comments

Beating myself at chess

https://log.schemescape.com/posts/diy/beating-myself-at-chess.html
35•zdw•4d ago•19 comments

World's largest functioning musical instrument: Wanamaker Organ in Philadelphia

https://en.wikipedia.org/wiki/Wanamaker_Organ
71•bookofjoe•6d ago•17 comments

Finance Industry Eyes Investment Opportunities in Venezuela

https://www.wsj.com/livecoverage/venezuela-strikes/card/finance-industry-eyes-investment-opportun...
34•clanky•2h ago•16 comments

ParadeDB (YC S23) Is Hiring Database Engineers

https://paradedb.notion.site/?p=172ea4ce9deb80898ef5d5097bd65544&pm=s
1•philippemnoel•12h ago