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.

US FAA says it will phase out floppy disks from air traffic control by 2028

https://www.reuters.com/world/us/us-faa-says-it-will-phase-out-floppy-disks-air-traffic-control-b...
98•ChrisArchitect•14h ago•103 comments

Tesla to wind down Cybertruck production

https://www.nbcnews.com/tech/tech-news/tesla-wind-cybertruck-production-years-poor-sales-markets-...
435•PLenz•6h ago•1068 comments

First steps in bare-metal programming using UEFI

https://kevinboone.me/efitest_index.html
76•LaSombra•1h ago•4 comments

Rune: A native GPU-rendered Rust UI framework for macOS, Windows, Linux and web

https://github.com/anomalyco/rune
63•mik3y•2h ago•37 comments

Size-It-Up (Game)

https://magnitudle.com/size-it-up
16•whoishiding•46m ago•4 comments

Gemini Omni 1.2 Flash

https://blog.google/innovation-and-ai/technology/developers-tools/introducing-gemini-omni-1-2-flash/
226•thisisauserid•5h ago•173 comments

We Know 15,579 Websites Are Infected. How Do We Tell Them?

https://scotthelme.co.uk/we-know-15-579-websites-are-infected-how-do-we-tell-them/
16•speckx•32m ago•3 comments

Blender's UI and Runtime: Much Faster Than GPUI

https://github.com/ppmpreetham/BUI
572•ppmpreetham•11h ago•234 comments

UpCodes (YC S17) is hiring SDR's to sell AI compliance software

https://up.codes/careers?utm_source=HN
1•Old_Thrashbarg•1h ago

Perplexity launches AI agents for work

https://www.perplexity.ai/en-GB/hub/blog/teammates-are-agents-for-complex-ongoing-work
13•cybermango•46m ago•7 comments

Deus Ex

https://www.filfre.net/2026/11/deus-ex/
235•cybersoyuz•3h ago•118 comments

Memorilla: Latent Semantic Memory for LLMs

https://arxiv.org/abs/2610.21375
11•handfuloflight•42m ago•0 comments

Devvm.dev: One VM for every project

https://devvm.dev/
14•luispa•1h ago•4 comments

Flawless UI-UX Skill 1.0.0

https://github.com/smokeeaasd/flawless-ui-ux/releases/tag/v1.0.0
10•99lcccss•53m ago•4 comments

Zero Hour: Telling time was a matter of survival and strategy during WWI (2014)

https://www.laphamsquarterly.org/roundtable/zero-hour
62•NaOH•23h ago•2 comments

Lippitt-Knoster in Practice (Field Notes for Managing Complex Projects)

https://sharedphysics.com/lippitt-knoster-in-practice-field-notes-for-managing-complex-projects/
35•goopthink•3h ago•1 comments

MTG-I2 First Images

https://www.eumetsat.int/mtg-i2-first-images
42•N19PEDL2•4h ago•8 comments

Living beyond the limits of survival: wood ants trapped in a gigantic pitfall (2016)

https://jhr.pensoft.net/articles.php?id=9096
135•hitekker•8h ago•43 comments

Scriptable GeoDNS: Leaving AWS for Bunny

https://vincent.bernat.ch/en/blog/2026-bunny-geodns
32•sshah03•2h ago•13 comments

Dutch 'idealist' bank ASN blocks non-Google Android, including GrapheneOS

https://github.com/PrivSec-dev/banking-apps-compat-report/issues/105
569•microtonal•9h ago•355 comments

Microsoft is winding down Oracle deal to rent AI cloud capacity

https://www.reuters.com/business/microsoft-is-winding-down-oracle-deal-rent-ai-cloud-capacity-blo...
29•brazukadev•42m ago•4 comments

Kalshi court losses pile up as judges refuse to block state gambling laws

https://arstechnica.com/tech-policy/2026/11/kalshi-court-losses-pile-up-as-judges-refuse-to-block...
23•Analemma_•43m ago•5 comments

Kugelblitz – Mac-Native Google Earth Alternative

https://apps.metaebene.me/en/kugelblitz
226•luoc•10h ago•60 comments

From Linux to Wikipedia: How Volunteers Build the Internet

https://thereader.mitpress.mit.edu/from-linux-to-wikipedia-how-volunteers-build-the-internet/
272•jonbaer•14h ago•87 comments

Show HN: AegisKernel – Zero-trust POSIX runtime for AI agents in <0.016ms

https://adikshatriyag-crypto.github.io/aegis-kernel/
5•adityawebde•1h ago•0 comments

Pliny – Letters – Book 7 Letter 27 (On Ghosts)

https://vroma.org/vromans/hwalker/Pliny/Pliny07-27-E.html?utm
4•yubblegum•48m ago•1 comments

Claude Code sends your email address to websites

https://github.com/anthropics/claude-code/issues/107757
1512•motoroco•20h ago•475 comments

PyLings: Solve Exercises and Learn Python

https://github.com/thesayfulla/pylings
6•thesayfulla•1h ago•0 comments

We've built an open-source feature flag server for 11 years

https://github.com/Unleash/unleash
116•ivarconr•7h ago•74 comments

Anthropic IPO valuation talks drop to $1.3T

https://epyhia.com/anthropic-ipo-valuation-talks-drop-to-1-3-trillion-as-major-investors
76•arbuge•1h ago•63 comments