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.

Why does it take so long to release black fan versions?

https://www.noctua.at/en/expertise/blog/how-can-it-take-so-long-to-release-black-fan-versions
95•buildbot•2h ago•29 comments

Spirit Airlines Is Winding Down All Operations

https://www.spiritrestructuring.com/
26•CaliforniaKarl•55m ago•18 comments

Job Postings for Software Engineers Are Rapidly Rising

https://www.citadelsecurities.com/news-and-insights/2026-global-intelligence-crisis/
155•delichon•5h ago•84 comments

Ti-84 Evo

https://education.ti.com/en/products/calculators/graphing-calculators/ti-84-evo
418•thatxliner•11h ago•368 comments

Ask.com has closed

https://www.ask.com/
205•supermdguy•3h ago•105 comments

Artemis II Photo Timeline

https://artemistimeline.com/#artemis-ii-walkout-nhq202604010003
168•geerlingguy•2d ago•12 comments

New research suggests people can communicate and practice skills while dreaming

https://www.newyorker.com/culture/annals-of-inquiry/its-possible-to-learn-in-our-sleep-should-we
316•XzetaU8•13h ago•180 comments

LFM2-24B-A2B: Scaling Up the LFM2 Architecture

https://www.liquid.ai/blog/lfm2-24b-a2b
25•nateb2022•2d ago•5 comments

To Restore an Island Paradise, Add Fungi

https://e360.yale.edu/digest/atoll-islands-sea-level-rise-fungi
50•Brajeshwar•2d ago•6 comments

K3k: Kubernetes in Kubernetes

https://github.com/rancher/k3k
29•jzebedee•3h ago•14 comments

CollectWise (YC F24) Is Hiring

https://www.ycombinator.com/companies/collectwise/jobs/rEWfZ6R-senior-forward-deployed-engineer
1•OBrien_1107•2h ago

Integer Overflow Checking Cost

https://danluu.com/integer-overflow/
15•iwsk•2d ago•4 comments

I'm Peter Roberts, immigration attorney who does work for YC and startups. AMA

152•proberts•16h ago•211 comments

Eka’s robotic claw feels like we're approaching a ChatGPT moment

https://www.wired.com/story/when-robots-have-their-chatgpt-moment-remember-these-pincers/
130•zdw•2d ago•172 comments

Lib0xc: A set of C standard library-adjacent APIs for safer systems programming

https://github.com/microsoft/lib0xc
135•wooster•12h ago•49 comments

I built the Playwright for desktop apps. 80% token savings

https://github.com/lahfir/agent-desktop
52•lahfir•5h ago•16 comments

A Gopher Meets a Crab

https://miren.dev/blog/gopher-meets-crab
5•radimm•2d ago•0 comments

Ask HN: Who is hiring? (May 2026)

253•whoishiring•16h ago•270 comments

Direct electrochemical black coffee quality appraisal using cyclic voltammetry

https://www.nature.com/articles/s41467-026-71526-5
44•bookofjoe•2d ago•13 comments

Show HN: WhatCable, a tiny menu bar app for inspecting USB-C cables

https://github.com/darrylmorley/whatcable
483•sleepingNomad•22h ago•141 comments

A Report on Burnout in Open Source Software Communities (2025) [pdf]

https://mirandaheath.website/static/oss_burnout_report_mh_25.pdf
62•susam•7h ago•12 comments

The smelly baby problem

https://www.worksinprogress.news/p/how-disposable-diapers-conquered
164•dionysou•2d ago•105 comments

Whohas – Command-line utility for cross-distro, cross-repository package search

https://github.com/whohas/whohas
140•peter_d_sherman•16h ago•32 comments

Create an MP4 video of a web page scrolling at a steady speed

https://github.com/upenn/web-scroll-video
19•shawnzam•4h ago•6 comments

Apocalypse Early Warning System

https://ews.kylemcdonald.net/
160•carlsborg•15h ago•87 comments

Chasing a SharedKey signature mismatch: fix azurerm_storage_table_entity

https://topaz.thecloudtheory.com/blog/debugging-table-entity-auth/
11•kamilmrzyglod•1d ago•4 comments

Show HN: Stop playing my matchstick puzzles, start building your own in seconds

https://mathstick.github.io
3•trangram•2h ago•3 comments

The gay jailbreak technique (2025)

https://github.com/Exocija/ZetaLib/blob/main/The%20Gay%20Jailbreak/The%20Gay%20Jailbreak.md
486•bobsmooth•14h ago•199 comments

City Learns Flock Accessed Cameras in Children's Gymnastics Room as a Sales Demo

https://www.404media.co/city-learns-flock-accessed-cameras-in-childrens-gymnastics-room-as-a-sale...
384•joshcsimmons•12h ago•104 comments

Whimsical Animations Course Open House

https://courses.joshwcomeau.com/wham/open-house/00-introduction
87•SpyCoder77•11h ago•9 comments