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.

There's a ridiculous amount of tech in a disposable vape

https://blog.jgc.org/2026/01/theres-ridiculous-amount-of-tech-in.html
303•abnercoimbre•1d ago•248 comments

1000 Blank White Cards

https://en.wikipedia.org/wiki/1000_Blank_White_Cards
149•eieio•5h ago•24 comments

ASCII Clouds

https://caidan.dev/portfolio/ascii_clouds/
167•majkinetor•6h ago•28 comments

A 40-line fix eliminated a 400x performance gap

https://questdb.com/blog/jvm-current-thread-user-time/
254•bluestreak•10h ago•53 comments

Every GitHub object has two IDs

https://www.greptile.com/blog/github-ids
215•dakshgupta•17h ago•56 comments

The Gleam Programming Language

https://gleam.run/
100•Alupis•6h ago•47 comments

Show HN: OSS AI agent that indexes and searches the Epstein files

https://epstein.trynia.ai/
78•jellyotsiro•7h ago•25 comments

Putting the "You" in CPU (2023)

https://cpu.land/
13•vinhnx•4d ago•0 comments

The truth behind the 2026 J.P. Morgan Healthcare Conference

https://www.owlposting.com/p/the-truth-behind-the-2026-jp-morgan
215•abhishaike•14h ago•40 comments

vLLM large scale serving: DeepSeek 2.2k tok/s/h200 with wide-ep

https://blog.vllm.ai/2025/12/17/large-scale-serving.html
101•robertnishihara•17h ago•14 comments

The $LANG Programming Language

178•dang•8h ago•35 comments

Show HN: 1D-Pong Game at 39C3

https://github.com/ogermer/1d-pong
25•oger•2d ago•2 comments

No management needed: anti-patterns in early-stage engineering teams

https://www.ablg.io/blog/no-management-needed
171•tonioab•14h ago•188 comments

The Emacs Widget Library: A Critique and Case Study

https://www.d12frosted.io/posts/2025-11-26-emacs-widget-library
64•whacked_new•2d ago•17 comments

Show HN: Cachekit – High performance caching policies library in Rust

https://github.com/OxidizeLabs/cachekit
32•failsafe•6h ago•6 comments

Show HN: The Tsonic Programming Language

https://tsonic.org
25•jeswin•15h ago•6 comments

Are two heads better than one?

https://eieio.games/blog/two-heads-arent-better-than-one/
163•evakhoury•16h ago•48 comments

Stop using natural language interfaces

https://tidepool.leaflet.pub/3mcbegnuf2k2i
73•steveklabnik•6h ago•20 comments

Handling secrets (somewhat) securely in shells

https://linus.schreibt.jetzt/posts/shell-secrets.html
53•todsacerdoti•4d ago•30 comments

The Tulip Creative Computer

https://github.com/shorepine/tulipcc
216•apitman•15h ago•50 comments

AI generated music barred from Bandcamp

https://old.reddit.com/r/BandCamp/comments/1qbw8ba/ai_generated_music_on_bandcamp/
758•cdrnsf•14h ago•535 comments

Sei (YC W22) Is Hiring a DevOps Engineer (India/In-Office/Chennai/Gurgaon)

https://www.ycombinator.com/companies/sei/jobs/Rn0KPXR-devops-platform-ai-infrastructure-engineer
1•ramkumarvenkat•8h ago

How to make a damn website (2024)

https://lmnt.me/blog/how-to-make-a-damn-website.html
190•birdculture•15h ago•57 comments

Agonist-Antagonist Myoneural Interface

https://www.media.mit.edu/projects/agonist-antagonist-myoneural-interface-ami/overview/
58•kaycebasques•5d ago•4 comments

Exa-d: How to store the web in S3

https://exa.ai/blog/exa-d
35•willbryk•7h ago•1 comments

Scott Adams has died

https://www.youtube.com/watch?v=Rs_JrOIo3SE
927•ekianjo•17h ago•1438 comments

Why we built our own background agent

https://builders.ramp.com/post/why-we-built-our-background-agent
95•jrsj•1d ago•17 comments

April 9, 1940 a Dish Best Served Cold

https://todayinhistory.blog/2021/04/09/april-9-1940-a-dish-best-served-cold/
27•vinnyglennon•4d ago•3 comments

When hardware goes end-of-life, companies need to open-source the software

https://www.marcia.no/words/eol
296•Marciplan•10h ago•90 comments

Show HN: Nogic – VS Code extension that visualizes your codebase as a graph

https://marketplace.visualstudio.com/items?itemName=Nogic.nogic
107•davelradindra•14h ago•43 comments