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.

Nvidia Reinstates Jensen Huang as CEO

https://www.cnbc.com/2026/11/23/nvidia-jensen-huang-ceo.html
2340•jaz•15h ago•3323 comments

Stalwart is now a drop-in replacement for Microsoft Exchange

https://stalw.art/blog/microsoft-exchange-replacement/
324•shaunpud•6h ago•152 comments

Ladybird is now in alpha

https://ladybird.org/posts/alpha/
1605•janvdberg•12h ago•376 comments

Drone Maps of Salvage Yards

https://salvageyarddrone.wordpress.com/
20•uptrails•1h ago•6 comments

Modernizing iperf/iperf3 and introducing fireperf

https://blog.daniel-baumann.ch/posts/20261122-1.html
26•edward•1d ago•1 comments

GPUI is getting its own repository

https://github.com/zed-industries/gpui
194•EvilGoose•8h ago•66 comments

Bored.com: Fun, interesting and cool websites to explore when bored

https://www.bored.com/
169•susam•8h ago•40 comments

The search for a top dark matter candidate

https://www.smithsonianmag.com/science-nature/the-search-for-a-top-dark-matter-candidate-was-losi...
31•apophatic•5h ago•12 comments

Making a dumb TV just smart enough

https://qsantos.fr/2026/11/19/making-a-dumb-tv-just-smart-enough/
23•andai•2h ago•5 comments

Declare is a UI language for you and your AI

https://davidtemkin.github.io/declarelang/
22•ilamont•2h ago•3 comments

"Dario is hyping the dangers so OSS models are illegal and he stays in control"

https://twitter.com/ylecun/status/2124550037912920090
1395•MrBuddyCasino•12h ago•774 comments

Per Arm's request, this site will be discontinued on 4 December 2026 :(

https://arm.jonpalmisc.com/
946•tech234a•9h ago•217 comments

Freeing the iPod Nano 5G

https://viktorkrapivin.com/blog/nano5g-priv-prvd
73•rpm_conservatio•6h ago•8 comments

New York Bans Subscription and Post-Purchase Fees on Cars

https://www.governor.ny.gov/news/money-your-pockets-governor-hochul-signs-bill-restricting-exploi...
116•DeepLogin•2h ago•38 comments

How photos were transmitted by wire in the 1930s (2024)

https://kottke.org/24/03/how-photos-were-transmitted-by-wire-in-the-1930s
29•sammatilda•3d ago•2 comments

Latent Introspection: LLMs Can Detect Prior Concept Injections

https://arxiv.org/abs/2602.20031
47•joecobb•6h ago•4 comments

Spacecraft reaches Mercury on second-ever mission to enter its orbit

https://www.theguardian.com/science/2026/nov/20/spacecraft-mercury-second-ever-mission-orbit-bepi...
322•geden•2d ago•106 comments

New material gets stronger the more it bends

https://source.washu.edu/2026/11/breakthrough-material-gets-stronger-the-more-it-bends/
5•giuliomagnifico•17h ago•2 comments

NariQ: BF16-level Qwen3.8-27B in a 10 GB file

https://huggingface.co/nari-labs/Qwen3.8-27B-NariQ-GGUF
144•toebee•15h ago•30 comments

Free alternative TV network built from the Internet Archive's forgotten videos

https://spelunkr.tv
964•SockThief•1d ago•169 comments

The Power of GraphQL, Without GraphQL

https://cobalt27.dev/
28•Shoetp•5h ago•16 comments

Hacking radiators

https://qsantos.fr/2026/11/20/hacking-radiators-for-fun-and-no-profit/
9•andai•2h ago•3 comments

VP ≠ VNP over Every Field

https://github.com/anthropics/formal-math/tree/main/vp-vnp
300•mikeryan52•6h ago•258 comments

Show HN: Juncts, one DM inbox for five apps that Claude and ChatGPT can work in

https://juncts.com/app?demo=1&utm_source=hackernews&utm_medium=launch&utm_campaign=launch-nov26
6•jlaufr•1h ago•0 comments

Derivative Flipping

http://blog.sigfpe.com/2026/11/derivative-flipping.html
87•dmit•2d ago•13 comments

Kagi Mail (public beta)

https://blog.kagi.com/kagi-mail-public-beta
387•rdmuser•11h ago•291 comments

GLM-5.4: Toward generalized coding with our first loop transformer

https://z.ai/blog/glm-5.4
1087•foohis•19h ago•353 comments

EasyPost (YC S13) Is Hiring

https://www.easypost.com/careers/
1•jstreebin•12h ago

Alcohol use reduces efficacy of immunotherapy by disrupting antitumor immunity

https://www.science.org/doi/10.1126/scisignal.aef1375
75•gumby•4h ago•52 comments

C++26 is done (again): ISO C++ meeting trip report

https://herbsutter.com/2026/11/21/c26-is-done-again-trip-report-november-2026-iso-c-standards-mee...
109•dverlaeckt80•1d ago•121 comments