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

Comments

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

Saying Goodbye to Agile

https://lewiscampbell.tech/blog/260414.html
19•matrixhelix•41m ago•1 comments

Claude Code Routines

https://code.claude.com/docs/en/routines
533•matthieu_bl•12h ago•309 comments

Dependency cooldowns turn you into a free-rider

https://calpaterson.com/deps.html
48•pabs3•3h ago•23 comments

Rare concert recordings are landing on the Internet Archive

https://techcrunch.com/2026/04/13/thousands-of-rare-concert-recordings-are-landing-on-the-interne...
589•jrm-veris•15h ago•170 comments

Not all elementary functions can be expressed with exp-minus-log

https://www.stylewarning.com/posts/not-all-elementary/
28•mmastrac•3h ago•9 comments

A communist Apple II and fourteen years of not knowing what you're testing

https://llama.gs/blog/index.php/2026/04/10/friday-archaeology-a-communist-apple-ii-and-fourteen-y...
96•major4x•4d ago•12 comments

Installing OpenBSD on the Pomera DM250 Writerdeck

https://jcs.org/2026/04/09/openbsd-dm250
20•djfergus•4d ago•6 comments

The Orange Pi 6 Plus

https://taoofmac.com/space/reviews/2026/04/11/1900
155•rcarmo•3d ago•111 comments

Stop Flock

https://stopflock.com
520•cdrnsf•7h ago•126 comments

Understanding Clojure's Persistent Vectors, pt. 1 (2013)

https://hypirion.com/musings/understanding-persistent-vector-pt-1
44•mirzap•4d ago•7 comments

Picasso's Guernica (Gigapixel)

https://guernica.museoreinasofia.es/gigapixel/#3/63.11/-120.59
85•guigar•3d ago•20 comments

5NF and Database Design

https://kb.databasedesignbook.com/posts/5nf/
149•petalmind•13h ago•56 comments

Turn your best AI prompts into one-click tools in Chrome

https://blog.google/products-and-platforms/products/chrome/skills-in-chrome/
144•xnx•12h ago•63 comments

Game: Print Gallery Of An Artist, A brief exploration of recursive spaces

https://managore.itch.io/print-gallery-of-an-artist
7•zdw•4d ago•1 comments

Let's talk space toilets

https://mceglowski.substack.com/p/lets-talk-space-toilets
162•zdw•1d ago•48 comments

The dangers of California's legislation to censor 3D printing

https://www.eff.org/deeplinks/2026/04/dangers-californias-legislation-censor-3d-printing
325•salkahfi•1d ago•327 comments

PCBWay sponsorship: full-size SD module for Arduino projects

https://www.colino.net/wordpress/archives/2026/04/10/pcbway-sponsorship-full-size-sd-module-for-a...
4•ibobev•4d ago•0 comments

Tell HN: Fiverr left customer files public and searchable

481•morpheuskafka•10h ago•99 comments

Don't feel like exercising? Maybe it's the wrong time of day for you

https://www.bbc.com/news/articles/cd6lzpxwx50o
25•tagawa•5h ago•8 comments

guide.world: A compendium of travel guides

https://guide.world/
94•firloop•5d ago•15 comments

Trusted access for the next era of cyber defense

https://openai.com/index/scaling-trusted-access-for-cyber-defense/
72•surprisetalk•9h ago•49 comments

I wrote to Flock's privacy contact to opt out of their domestic spying program

https://honeypot.net/2026/04/14/i-wrote-to-flocks-privacy.html
565•speckx•11h ago•229 comments

Backblaze has stopped backing up OneDrive and Dropbox folders and maybe others

https://rareese.com/posts/backblaze/
1020•rrreese•20h ago•619 comments

Show HN: Plain – The full-stack Python framework designed for humans and agents

https://github.com/dropseed/plain
78•focom•11h ago•28 comments

Troubleshooting Email Delivery to Microsoft Users

https://rozumem.xyz/posts/14
55•rozumem•2d ago•14 comments

Show HN: LangAlpha – what if Claude Code was built for Wall Street?

https://github.com/ginlix-ai/langalpha
127•zc2610•14h ago•39 comments

OpenSSL 4.0.0

https://github.com/openssl/openssl/releases/tag/openssl-4.0.0
234•petecooper•11h ago•76 comments

Apple App Store threatened to remove Grok over deepfakes: Letter

https://www.nbcnews.com/tech/tech-news/apple-threat-remove-grok-app-store-deepfake-letter-musk-x-...
71•donohoe•5h ago•34 comments

Introspective Diffusion Language Models

https://introspective-diffusion.github.io/
253•zagwdt•21h ago•45 comments

DaVinci Resolve – Photo

https://www.blackmagicdesign.com/products/davinciresolve/photo
1082•thebiblelover7•1d ago•271 comments