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.

Sharp

https://apple.github.io/ml-sharp/
55•dvrp•1h ago•9 comments

Quill OS: An open-source OS for Kobo's eReaders

https://quill-os.org/
174•Curiositry•5h ago•59 comments

8M users' AI conversations sold for profit by "privacy" extensions

https://www.koi.ai/blog/urban-vpn-browser-extension-ai-conversations-data-collection
231•takira•2h ago•72 comments

Native vs. emulation: World of Warcraft game performance on Snapdragon X Elite

https://rkblog.dev/posts/pc-hardware/pc-on-arm/x86_versus_arm_native_game/
37•geekman7473•5h ago•12 comments

“Are you the one?” is free money

https://blog.owenlacey.dev/posts/are-you-the-one-is-free-money/
242•samwho•3d ago•52 comments

Nature's many attempts to evolve a Nostr

https://newsletter.squishy.computer/p/natures-many-attempts-to-evolve-a
149•fiatjaf•5d ago•79 comments

Essential Semiconductor Physics [pdf]

https://nanohub.org/resources/43623/download/Essential_Semiconductor_Physics.pdf
143•akshatjiwan•2d ago•6 comments

Show HN: I designed my own 3D printer motherboard

https://github.com/KaiPereira/Cheetah-MX4-Mini
28•kaipereira•1w ago•10 comments

Economics of Orbital vs. Terrestrial Data Centers

https://andrewmccalip.com/space-datacenters
69•flinner•7h ago•118 comments

Ford kills the All-Electric F-150

https://www.wired.com/story/ford-kills-electric-f-150-lightning-for-hybrid/
286•sacred-rat•7h ago•442 comments

Umbrel – Personal Cloud

https://umbrel.com
155•oldfuture•10h ago•90 comments

The Bob Dylan concert for just one person

https://www.flaggingdown.com/p/the-bob-dylan-concert-for-just-one
57•NaOH•5h ago•10 comments

Rollstack (YC W23) is hiring multiple software engineers (TypeScript) US/Canada

https://www.ycombinator.com/companies/rollstack-2/jobs/QPqpb1n-software-engineer-typescript-us-ca...
1•yjallouli•3h ago

In Defense of Matlab Code

https://runmat.org/blog/in-defense-of-matlab-whiteboard-style-code
94•finbarr1987•3d ago•99 comments

Secret Documents Show Pepsi and Walmart Colluded to Raise Food Prices

https://www.thebignewsletter.com/p/secret-documents-show-pepsi-and-walmart
313•connor11528•8h ago•92 comments

Light intensity steers molecular assemblies into 1D, 2D or 3D structures

https://phys.org/news/2025-11-intensity-molecular-1d-2d-3d.html
9•PaulHoule•5d ago•0 comments

Chafa: Terminal Graphics for the 21st Century

https://hpjansson.org/chafa/
126•birdculture•11h ago•22 comments

A kernel bug froze my machine: Debugging an async-profiler deadlock

https://questdb.com/blog/async-profiler-kernel-bug/
71•bluestreak•8h ago•14 comments

Understanding carriage

https://seths.blog/2025/12/understanding-carriage/
31•herbertl•5d ago•6 comments

SoundCloud confirms breach after member data stolen, VPN access disrupted

https://www.bleepingcomputer.com/news/security/soundcloud-confirms-breach-after-member-data-stole...
71•technonerd•3h ago•9 comments

John Updike wrote it all down

https://newrepublic.com/article/201598/john-updike-wrote
11•samclemens•6d ago•1 comments

Cosmic-ray bath in a past supernova gives birth to Earth-like planets

https://www.science.org/doi/10.1126/sciadv.adx7892
88•toomuchtodo•12h ago•32 comments

The appropriate amount of effort is zero

https://expandingawareness.org/blog/the-appropriate-amount-of-effort-is-zero/
84•gmays•9h ago•49 comments

Canada's Carney called out for 'utilizing' British spelling

https://www.bbc.com/news/articles/cj69d89l8l5o
5•haunter•8h ago•2 comments

Fix HDMI-CEC weirdness with a Raspberry Pi and a $7 cable

https://johnlian.net/posts/hdmi-cec/
225•jlian•7h ago•110 comments

We are discontinuing the dark web report

https://support.google.com/websearch/answer/16767242?hl=en
120•satertek•14h ago•36 comments

Upcoming Changes to Let's Encrypt Certificates

https://community.letsencrypt.org/t/upcoming-changes-to-let-s-encrypt-certificates/243873
277•schmuckonwheels•10h ago•214 comments

I'm Kenyan. I don't write like ChatGPT, ChatGPT writes like me

https://marcusolang.substack.com/p/im-kenyan-i-dont-write-like-chatgpt
616•florian_s•17h ago•395 comments

How does Windows synthesize CF_Unicode­TEXT from CF_TEXT and vice versa?

https://devblogs.microsoft.com/oldnewthing/20251209-00/?p=111854
3•ibobev•5d ago•0 comments

“Super secure” messaging app leaks everyone's phone number

https://ericdaigle.ca/posts/super-secure-maga-messaging-app-leaks-everyones-phone-number/
554•e_daigle•10h ago•264 comments