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•10mo ago

Comments

LegionMammal978•9mo 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•9mo 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•9mo 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.

US Court of Appeals: TOS may be updated by email, use can imply consent [pdf]

https://cdn.ca9.uscourts.gov/datastore/memoranda/2026/03/03/25-403.pdf
154•dryadin•3h ago•67 comments

Grammarly is offering ‘expert’ AI reviews from famous dead and living writers

https://www.wired.com/story/grammarly-is-offering-expert-ai-reviews-from-your-favorite-authors-de...
31•jmsflknr•4d ago•34 comments

Show HN: Mcp2cli – One CLI for every API, 96-99% fewer tokens than native MCP

https://github.com/knowsuchagency/mcp2cli
69•knowsuchagency•4h ago•35 comments

Agent Safehouse – macOS-native sandboxing for local agents

https://agent-safehouse.dev/
568•atombender•13h ago•141 comments

Microscopes can see video on a laserdisc

https://www.youtube.com/watch?v=qZuR-772cks
434•zdw•1d ago•52 comments

PCB devboard the size of a USB-C plug

https://github.com/Dieu-de-l-elec/AngstromIO-devboard
173•zachlatta•1d ago•33 comments

Ask HN: What Are You Working On? (March 2026)

146•david927•9h ago•501 comments

We should revisit literate programming in the agent era

https://silly.business/blog/we-should-revisit-literate-programming-in-the-agent-era/
234•horseradish•13h ago•139 comments

Every single board computer I tested in 2025

https://bret.dk/every-single-board-computer-i-tested-in-2025/
167•speckx•3d ago•50 comments

FrameBook

https://fb.edoo.gg
430•todsacerdoti•18h ago•72 comments

The death of social media is the renaissance of RSS (2025)

https://www.smartlab.at/rss-revival-life-after-social-media/
135•jruohonen•5h ago•75 comments

How the Sriracha guys screwed over their supplier

https://old.reddit.com/r/KitchenConfidential/comments/1ro61g2/how_the_sriracha_guys_screwed_over_...
173•thunderbong•5h ago•38 comments

Linux Internals: How /proc/self/mem writes to unwritable memory (2021)

https://offlinemark.com/an-obscure-quirk-of-proc/
80•medbar•11h ago•18 comments

My Homelab Setup

https://bryananthonio.com/blog/my-homelab-setup/
231•photon_collider•17h ago•150 comments

Artificial-life: A simple (300 lines of code) reproduction of Computational Life

https://github.com/Rabrg/artificial-life
110•tosh•13h ago•12 comments

I love email (2023)

https://blog.xoria.org/email/
9•surprisetalk•3d ago•1 comments

I made a programming language with M&Ms

https://mufeedvh.com/posts/i-made-a-programming-language-with-mnms/
80•tosh•15h ago•34 comments

Why can't you tune your guitar? (2019)

https://www.ethanhein.com/wp/2019/why-cant-you-tune-your-guitar/
209•digitallogic•4d ago•148 comments

My “grand vision” for Rust

https://blog.yoshuawuyts.com/a-grand-vision-for-rust/
187•todsacerdoti•4d ago•171 comments

Living human brain cells play DOOM on a CL1 [video]

https://www.youtube.com/watch?v=yRV8fSw6HaE
189•kevinak•18h ago•185 comments

Humanoid robot: The evolution of Kawasaki’s challenge

https://kawasakirobotics.com/in/blog/202511_kaleido/
14•hhs•3d ago•2 comments

Pushing and Pulling: Three reactivity algorithms

https://jonathan-frere.com/posts/reactivity-algorithms/
99•frogulis•1d ago•16 comments

WSL Manager

https://github.com/bostrot/wsl2-distro-manager
104•gballan•15h ago•55 comments

Z80 Sans – a disassembler in a font (2024)

https://github.com/nevesnunes/z80-sans
113•pabs3•4d ago•12 comments

Triumph of the toons: how animation came to rule the box office

https://economist.com/culture/2026/03/05/triumph-of-the-toons-how-animation-came-to-rule-the-box-...
17•andsoitis•3d ago•18 comments

The legendary Mojave Phone Booth is back (2013)

https://dailydot.com/mojave-phone-booth-back-number
32•1970-01-01•2d ago•6 comments

Ask HN: How to be alone?

464•sillysaurusx•22h ago•333 comments

Show HN: Skir – like Protocol Buffer but better

https://skir.build/
88•gepheum•16h ago•45 comments

Show HN: I built a real-time OSINT dashboard pulling 15 live global feeds

https://github.com/BigBodyCobain/Shadowbroker
235•vancecookcobxin•14h ago•99 comments

Case Study: lynnandtonic.com 2025 refresh

https://lynnandtonic.com/thoughts/entries/case-study-2025-refresh/
16•surprisetalk•3d ago•2 comments