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

Comments

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

Doing gigabit Ethernet over my British phone wires

https://thehftguy.com/2026/01/22/doing-gigabit-ethernet-over-my-british-phone-wires/
150•user5994461•2h ago•81 comments

Many Small Queries Are Efficient in SQLite

https://www.sqlite.org/np1queryprob.html
13•tosh•1h ago•3 comments

Internet Archive's Storage

https://blog.dshr.org/2026/01/internet-archives-storage.html
189•zdw•3d ago•43 comments

Show HN: Coi – A language that compiles to WASM, beats React/Vue

77•io_eric•3d ago•30 comments

Unrolling the Codex agent loop

https://openai.com/index/unrolling-the-codex-agent-loop/
367•tosh•16h ago•166 comments

80386 Multiplication and Division

https://nand2mario.github.io/posts/2026/80386_multiplication_and_division/
59•nand2mario•6h ago•12 comments

Proof of Corn

https://proofofcorn.com/
406•rocauc•19h ago•276 comments

Modetc: Move your dotfiles from kernel space

https://maxwell.eurofusion.eu/git/rnhmjoj/modetc
23•todsacerdoti•4h ago•9 comments

Management Time: Who's Got the Monkey? [pdf]

https://www.med.unc.edu/uncaims/wp-content/uploads/sites/764/2014/03/Oncken-_-Wass-Who_s-Got-the-...
11•rintrah•4d ago•1 comments

Extracting verified C++ from the Rocq theorem prover at Bloomberg

https://bloomberg.github.io/crane/
67•clarus•4d ago•4 comments

Traintrackr – Live LED Maps

https://www.traintrackr.co.uk/
58•recursion•5d ago•22 comments

Gas Town's agent patterns, design bottlenecks, and vibecoding at scale

https://maggieappleton.com/gastown
351•pavel_lishin•20h ago•359 comments

Some C habits I employ for the modern day

https://www.unix.dog/~yosh/blog/c-habits-for-me.html
175•signa11•5d ago•100 comments

“Let people help” – Advice that made a big difference to a grieving widow

https://www.npr.org/2026/01/20/nx-s1-5683170/let-them-the-small-bit-of-advice-that-made-a-big-dif...
78•NaOH•9h ago•14 comments

Show HN: I built a space travel calculator using Vanilla JavaScript

https://cosmic-odometer.vercel.app/
41•captainnemo729•3h ago•22 comments

Banned C++ features in Chromium

https://chromium.googlesource.com/chromium/src/+/main/styleguide/c++/c++-features.md
194•szmarczak•16h ago•160 comments

Telli (YC F24) is hiring eng, design, growth [on-site, Berlin]

https://careers.telli.com/
1•sebselassie•6h ago

Comma openpilot – Open source driver-assistance

https://comma.ai
300•JumpCrisscross•12h ago•163 comments

Ask HN: What's the current best local/open speech-to-speech setup?

182•dsrtslnd23•1d ago•45 comments

Microsoft gave FBI set of BitLocker encryption keys to unlock suspects' laptops

https://techcrunch.com/2026/01/23/microsoft-gave-fbi-a-set-of-bitlocker-encryption-keys-to-unlock...
901•bookofjoe•19h ago•577 comments

New YC homepage

https://www.ycombinator.com/
265•sarreph•18h ago•133 comments

Booting from a vinyl record (2020)

https://boginjr.com/it/sw/dev/vinyl-boot/
323•yesturi•1d ago•110 comments

I Like GitLab

https://www.whileforloop.com/en/blog/2026/01/21/i-like-gitlab/
8•lukas346•2h ago•3 comments

Mental Models (2018)

https://fs.blog/mental-models/
105•hahahacorn•15h ago•14 comments

Proton spam and the AI consent problem

https://dbushell.com/2026/01/22/proton-spam/
523•dbushell•1d ago•374 comments

KORG phase8 – Acoustic Synthesizer

https://www.korg.com/us/products/dj/phase8/
241•bpierre•22h ago•108 comments

Route leak incident on January 22, 2026

https://blog.cloudflare.com/route-leak-incident-january-22-2026/
154•nomaxx117•19h ago•49 comments

Air traffic control: the IBM 9020

https://computer.rip/2026-01-17-air-traffic-control-9020.html
47•pinewurst•5d ago•4 comments

The tech monoculture is finally breaking

http://www.jasonwillems.com/technology/2025/12/17/Tech-Is-Fun-Again/
207•at1as•21h ago•278 comments

Show HN: Whosthere: A LAN discovery tool with a modern TUI, written in Go

https://github.com/ramonvermeulen/whosthere
253•rvermeulen98•1d ago•85 comments