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.

507 Mechanical Movements

https://507movements.com/
86•helloplanets•1h ago•11 comments

Pollen Robotics (Hugging Face) Microduck

https://pollen-robotics.com/microduck/
246•robotswantdata•4h ago•99 comments

Emacs 31: An unofficial guide to Markdown-ts-mode

https://rahuljuliato.com/posts/markdown-ts-mode-emacs-31
65•RahulMJ•2h ago•20 comments

Nvidia agrees to acquire Hugging Face for $13B

https://www.businessinsider.com/nvidia-in-talks-to-buy-hugging-face-13-billion-dollars-2026-8
1606•mfiguiere•14h ago•737 comments

CoMaps integration with the wider FLOSS ecosystem – CoMaps

https://www.comaps.app/news/2026-08-23/comaps-integration-with-the-wider-floss-ecosystem/
66•janandonly•2h ago•5 comments

Launching Route 53 Files

https://www.daemonology.net/blog/2026-08-27-Launching-Route-53-Files.html
23•louis-paul•59m ago•9 comments

Software engineering is about managing complexity

https://hack8s.com/422/once-again-software-engineering-is-about-managing-complexity
25•justorius•1h ago•4 comments

MIT's Ad Hoc Committee on AI Use in Teaching, Learning, and Research Training

https://aiandeducation.mit.edu/report/
38•pbui•2h ago•24 comments

Harness Engineering

https://Habitat-Thinking.github.io/ai-literacy-superpowers/plugins/ai-literacy-superpowers/explan...
78•tomrod•1h ago•35 comments

Trade (and Tariffs)

https://xkcd.com/3290/
164•throw0101d•1h ago•51 comments

Show HN: Restoredrill – proves your Postgres backups restore

https://github.com/ahmadpiran/restoredrill
12•ahmadpiran•1h ago•6 comments

French CII's Mitra-15 in SIMH. Work in Progress

https://github.com/JPLeRouzic/Mitra-15-for-SIMH
9•JPLeRouzic•1h ago•1 comments

Adentris (YC P25) Is Hiring

https://www.ycombinator.com/companies/adentris/jobs/ZpMXZ0C-founding-engineer-ai-rcm-healthcare-p...
1•SergeyYudovskiy•3h ago

Confdiff – semantic diff for config files (JSON/YAML/TOML) that redacts secrets

https://github.com/esperanza-volkov/confdiff
14•esperanzavolkov•2h ago•3 comments

Mechanical Turk shutting down September 30

https://www.mturk.com/
485•tmp10423288442•15h ago•149 comments

Show HN: RealDiff – runtime behavior diffing for pull requests (six languages)

https://github.com/issacnitin/RealDiff
23•issacnitin•2h ago•4 comments

Tell HN: PayPal Blocks GrapheneOS

326•leumon•5h ago•178 comments

Asahi Linux Progress Report: Linux 7.2

https://asahilinux.org/2026/08/progress-report-7-2/
366•pizzaiolo•17h ago•189 comments

US Government Designates Host of Noblogs.org a "Global Terrorist"

https://crimethinc.com/2026/08/27/us-government-designates-host-of-noblogsorg-a-global-terrorist
125•robtherobber•2h ago•41 comments

Apple threat notifications and spyware: what everyone should know

https://www.accessnow.org/apple-threat-notifications-and-spyware/
17•ricobecks•1h ago•3 comments

Peter Cullen, Voice of Optimus Prime in 'Transformers,' Dies at 85

https://www.hollywoodreporter.com/movies/movie-news/peter-cullen-optimus-prime-transformers-eeyor...
14•cocacola1•42m ago•1 comments

Show HN: The load-bearing vocabulary of Claude

https://louisabraham.github.io/load-bearing/
55•Labo333•6h ago•9 comments

Six Months of Writing Code Exclusively with Agents

https://blog.exe.dev/engineering-with-ai
42•bryanmikaelian•1h ago•42 comments

CEO fired developers to make room for AI. Developers create open source AI CEO

https://github.com/SenteLabsAI/OpenExecutive
843•GrumpySciGuy•13h ago•576 comments

Stripe acquires Clerky

https://www.clerky.com/blog/clerky-is-joining-stripe
234•zakshay•18h ago•54 comments

Worst-case glacial lake flood scenarios in a transboundary Himalayan basin 2022

https://nhess.copernicus.org/articles/22/3765/2022/nhess-22-3765-2022.html
253•totetsu•17h ago•180 comments

Did Meta's Big Settlement Actually Help It?

https://www.nytimes.com/2026/08/27/business/dealbook/meta-settlement-teens.html
33•thm•2h ago•29 comments

The Hugging Face incident and the road ahead

https://openai.com/index/hugging-face-incident-and-the-road-ahead/
315•amrrs•20h ago•405 comments

The Harness Is the Thing

https://scott-fryxell.github.io/blog/the-harness-is-the-thing/
184•sfryxell•22h ago•102 comments

Zohran and the Short Link

https://iamwillwang.com/notes/zohran-and-the-short-link/
262•wxw•15h ago•155 comments