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.

Is Mozilla trying hard to kill itself?

https://infosec.press/brunomiguel/is-mozilla-trying-hard-to-kill-itself
315•pabs3•2h ago•268 comments

AI will make formal verification go mainstream

https://martin.kleppmann.com/2025/12/08/ai-formal-verification.html
668•evankhoury•14h ago•342 comments

TLA+ Modeling Tips

http://muratbuffalo.blogspot.com/2025/12/tla-modeling-tips.html
46•birdculture•3h ago•4 comments

alpr.watch

https://alpr.watch/
805•theamk•19h ago•378 comments

Modern SID chip substitutes [video]

https://www.youtube.com/watch?v=nooPmXxO6K0
11•vismit2000•3d ago•0 comments

No Graphics API

https://www.sebastianaaltonen.com/blog/no-graphics-api
680•ryandrake•16h ago•121 comments

Announcing the Beta release of ty

https://astral.sh/blog/ty
637•gavide•15h ago•119 comments

AI's real superpower: consuming, not creating

https://msanroman.io/blog/ai-consumption-paradigm
32•firefoxd•3h ago•24 comments

Playing Santa does things to a man. what it did to bob rutan was even stranger

https://www.esquire.com/lifestyle/a69597294/santaland-bob-rutan/
17•Lightbody•3d ago•3 comments

GPT Image 1.5

https://openai.com/index/new-chatgpt-images-is-here/
452•charlierguo•17h ago•208 comments

Pricing Changes for GitHub Actions

https://resources.github.com/actions/2026-pricing-changes-for-github-actions/
677•kevin-david•18h ago•739 comments

No AI* Here – A Response to Mozilla's Next Chapter

https://www.waterfox.com/blog/no-ai-here-response-to-mozilla/
368•MrAlex94•13h ago•215 comments

Annual Production of 1/72 (22mm) scale plastic soldiers, 1958-2025

https://plasticsoldierreview.com/ShowFeature.aspx?id=27
41•YeGoblynQueenne•3d ago•25 comments

VA Linux: The biggest dotcom IPO

https://dfarq.homeip.net/va-linux-the-biggest-dotcom-ipo/
68•giuliomagnifico•5d ago•27 comments

Subsets (YC S23) is hiring engineers in Copenhagen, Denmark

https://www.workatastartup.com/companies/subsets
1•Oliverbrandt•5h ago

Show HN: I built a WebMIDI sequencer to control my hardware synths

https://www.simplychris.ai/droplets
23•simplychris•5d ago•7 comments

40 percent of fMRI signals do not correspond to actual brain activity

https://www.tum.de/en/news-and-events/all-news/press-releases/details/40-percent-of-mri-signals-d...
456•geox•22h ago•179 comments

Thin desires are eating life

https://www.joanwestenberg.com/thin-desires-are-eating-your-life/
528•mitchbob•1d ago•191 comments

Mozilla appoints new CEO Anthony Enzor-Demeo

https://blog.mozilla.org/en/mozilla/leadership/mozillas-next-chapter-anthony-enzor-demeo-new-ceo/
526•recvonline•22h ago•791 comments

I ported JustHTML from Python to JavaScript with Codex CLI and GPT-5.2 in hours

https://simonwillison.net/2025/Dec/15/porting-justhtml/
180•pbowyer•13h ago•105 comments

P: Formal Modeling and Analysis of Distributed (Event-Driven) Systems

https://github.com/p-org/P
14•Davidbrcz•4h ago•2 comments

Living Particle System

https://creative-art-points.vercel.app/
10•lovegrenoble•4d ago•0 comments

Introduction to Software Development Tooling (2024)

https://bernsteinbear.com/isdt/
82•vismit2000•10h ago•11 comments

Japan to revise romanization rules for first time in 70 years

https://www.japantimes.co.jp/news/2025/08/21/japan/panel-hepburn-style-romanization/
211•rgovostes•1d ago•184 comments

Show HN: Titan – JavaScript-first framework that compiles into a Rust server

https://www.npmjs.com/package/@ezetgalaxy/titan
41•soham_byte•6d ago•21 comments

Show HN: Mephisto – A RAM-only, ad-free disposable email PWA built with React

https://mephistomail.site
5•benmxrt•2h ago•3 comments

Sega Channel: VGHF Recovers over 100 Sega Channel ROMs (and More)

https://gamehistory.org/segachannel/
260•wicket•22h ago•41 comments

The World Happiness Report is beset with methodological problems

https://yaschamounk.substack.com/p/the-world-happiness-report-is-a-sham
137•thatoneengineer•1d ago•169 comments

Nvidia Nemotron 3 Family of Models

https://research.nvidia.com/labs/nemotron/Nemotron-3/
218•ewt-nv•1d ago•42 comments

Dafny: Verification-Aware Programming Language

https://dafny.org/
82•handfuloflight•13h ago•28 comments