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.

A new Android malware from Google

https://f-droid.org/2026/07/01/adv-malware.html
628•drewfax•7h ago•257 comments

Kimi K2.7 Code is generally available in GitHub Copilot

https://github.blog/changelog/2026-07-01-kimi-k2-7-is-now-available-in-github-copilot/
173•unliftedq•6h ago•68 comments

The Fall of the Theorem Economy

https://davidbessis.substack.com/p/the-fall-of-the-theorem-economy
60•varjag•2h ago•8 comments

Oomwoo, an open-source robot vacuum you build yourself

https://makerspet.com/blog/building-an-open-source-robot-vacuum-meet-oomwoo/
325•devicelimit•10h ago•60 comments

ZCode – Harness for GLM-5.2

https://zcode.z.ai/en
408•chvid•12h ago•297 comments

Asymmetric Quantization: Near-Lossless Retrieval with 97% Storage Reduction

https://www.mixedbread.com/blog/asymmetric-quant
38•breadislove•2d ago•6 comments

My Favorite Keyboards

https://fabiensanglard.net/keyboards/index.html
37•tmach32•3d ago•16 comments

Bring back crappy forums

https://tedium.co/2026/07/01/online-web-forums-retrospective/
298•pentagrama•8h ago•186 comments

What to learn to be a graphics programmer

https://blog.demofox.org/2026/07/01/what-to-learn-to-be-a-graphics-programmer/
361•atan2•16h ago•183 comments

FFmpeg 9.1's new AAC encoder

https://hydrogenaudio.org/index.php/topic,129691.0.html
386•ledoge•20h ago•118 comments

Senior SWE-Bench: open-source benchmark that assesses agents as senior engineers

https://senior-swe-bench.snorkel.ai/
96•matt_d•7h ago•72 comments

Opening up 'Zero-Knowledge Proof' technology to promote privacy in age assurance

https://blog.google/innovation-and-ai/technology/safety-security/opening-up-zero-knowledge-proof-...
166•consumer451•12h ago•159 comments

How do wombats poop cubes?

https://www.science.org/content/article/how-do-wombats-poop-cubes-scientists-get-bottom-mystery
130•bushwart•1d ago•66 comments

Aerial Photographs (2017)

https://www.toronto.ca/city-government/accountability-operations-customer-service/access-city-inf...
10•surprisetalk•2d ago•0 comments

Ask HN: Who is hiring? (July 2026)

204•whoishiring•19h ago•214 comments

CursorBench 3.1

https://cursor.com/evals
69•handfuloflight•5h ago•42 comments

Google loses fight over record $4.7B EU antitrust fine

https://www.cnbc.com/2026/07/02/alphabet-google-android-eu-antitrust-fine-4-1-billion-euro-appeal...
97•boshomi•2h ago•82 comments

Why jet engines aren't made in China

https://aakash.substack.com/p/why-jet-engines-arent-made-in-china
169•paulpauper•1d ago•153 comments

Weave Robotics launches Isaac 1, a $7,999 home robot with Fall 2026 deliveries

https://www.weaverobotics.com/isaac-1
186•ryanmerket•16h ago•267 comments

Qualcomm Linux 2.0

https://www.qualcomm.com/developer/blog/2026/06/qualcomm-linux-2-now-available
111•gilgamesh3•13h ago•47 comments

Creating a Personalised Bin Calendar

https://alexwlchan.net/2026/bin-calendar/
3•surprisetalk•2d ago•0 comments

For first time, a cell built from scratch grows and divides

https://www.quantamagazine.org/for-the-first-time-a-cell-built-from-scratch-grows-and-divides-202...
862•defrost•20h ago•278 comments

Monetization Gateway: Charge for any resource behind Cloudflare via x402

https://blog.cloudflare.com/monetization-gateway/
302•soheilpro•20h ago•212 comments

The Underhanded C Contest

https://underhanded-c.org/
98•ccabraldev•12h ago•11 comments

Learn Vim motions with an ice-cream van

https://thisismodest.com/vimscoops/
77•marcusmichaels•16h ago•21 comments

Show HN: Searchable directory of 22k+ products from worker-owned co-ops

https://www.workerowned.info/
359•IESAI_ski•14h ago•68 comments

The Wisdom of Quinn the Eskimo (Apple Developer Technical Support Engineer)

https://github.com/macshome/The-Wisdom-of-Quinn
27•gregsadetsky•2d ago•8 comments

Ask HN: Who wants to be hired? (July 2026)

132•whoishiring•19h ago•323 comments

Chip Off The Old Block

https://www.astralcodexten.com/p/chip-off-the-old-block
87•paulpauper•13h ago•10 comments

Proliferate (YC S25) Is Hiring

https://www.ycombinator.com/companies/proliferate/jobs/mMHvKR9-founding-product-engineer
1•pablo24602•13h ago