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

Comments

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

Anthropic acquires Bun

https://bun.com/blog/bun-joins-anthropic
623•ryanvogel•1h ago•283 comments

100k TPS over a billion rows: the unreasonable effectiveness of SQLite

https://andersmurphy.com/2025/12/02/100000-tps-over-a-billion-rows-the-unreasonable-effectiveness...
128•speckx•1h ago•34 comments

Claude 4.5 Opus' Soul Document

https://simonwillison.net/2025/Dec/2/claude-soul-document/
62•the-needful•42m ago•20 comments

Amazon launches Trainium3

https://techcrunch.com/2025/12/02/amazon-releases-an-impressive-new-ai-chip-and-teases-a-nvidia-f...
33•thnaks•44m ago•10 comments

I designed and printed a custom nose guard to help my dog with DLE

https://snoutcover.com/billie-story
209•ragswag•2d ago•32 comments

Learning music with Strudel

https://terryds.notion.site/Learning-Music-with-Strudel-2ac98431b24180deb890cc7de667ea92
285•terryds•6d ago•68 comments

OpenAI declares 'code red' as Google catches up in AI race

https://www.theverge.com/news/836212/openai-code-red-chatgpt
125•goplayoutside•4h ago•136 comments

Mistral 3 family of models released

https://mistral.ai/news/mistral-3
507•pember•4h ago•157 comments

Cursed circuits: charge pump voltage halver

https://lcamtuf.substack.com/p/cursed-circuits-charge-pump-voltage
8•surprisetalk•1h ago•0 comments

Zig's new plan for asynchronous programs

https://lwn.net/SubscriberLink/1046084/4c048ee008e1c70e/
116•messe•5h ago•95 comments

YesNotice

https://infinitedigits.co/docs/software/yesnotice/
108•surprisetalk•1w ago•45 comments

Poka Labs (YC S24) Is Hiring a Founding Engineer

https://www.ycombinator.com/companies/poka-labs/jobs/RCQgmqB-founding-engineer
1•arbass•2h ago

Nixtml: Static website and blog generator written in Nix

https://github.com/arnarg/nixtml
66•todsacerdoti•4h ago•24 comments

Addressing the adding situation

https://xania.org/202512/02-adding-integers
231•messe•8h ago•72 comments

The Junior Hiring Crisis

https://people-work.io/blog/junior-hiring-crisis/
87•mooreds•2h ago•83 comments

4.3M Browsers Infected: Inside ShadyPanda's 7-Year Malware Campaign

https://www.koi.ai/blog/4-million-browsers-infected-inside-shadypanda-7-year-malware-campaign
54•janpio•3h ago•14 comments

Advent of Compiler Optimisations 2025

https://xania.org/202511/advent-of-compiler-optimisation
291•vismit2000•9h ago•49 comments

Python Data Science Handbook

https://jakevdp.github.io/PythonDataScienceHandbook/
152•cl3misch•7h ago•32 comments

School Cell Phone Bans and Student Achievement (NBER Digest)

https://www.nber.org/digest/202512/school-cell-phone-bans-and-student-achievement
20•harias•1h ago•13 comments

Microsoft won't let me pay a $24 bill, blocking thousands in Azure spending

40•Javin007•58m ago•21 comments

Lowtype: Elegant Types in Ruby

https://codeberg.org/Iow/type
38•birdculture•4d ago•18 comments

Code Wiki: Accelerating your code understanding

https://developers.googleblog.com/en/introducing-code-wiki-accelerating-your-code-understanding/
7•geoffbp•6d ago•2 comments

Apple Releases Open Weights Video Model

https://starflow-v.github.io
400•vessenes•14h ago•133 comments

Show HN: Marmot – Single-binary data catalog (no Kafka, no Elasticsearch)

https://github.com/marmotdata/marmot
73•charlie-haley•4h ago•17 comments

What will enter the public domain in 2026?

https://publicdomainreview.org/features/entering-the-public-domain/2026/
444•herbertl•16h ago•306 comments

A series of vignettes from my childhood and early career

https://www.jasonscheirer.com/weblog/vignettes/
118•absqueued•7h ago•83 comments

YouTube increases FreeBASIC performance (2019)

https://freebasic.net/forum/viewtopic.php?t=27927
143•giancarlostoro•2d ago•37 comments

Anthropic Acquires Bun

https://www.anthropic.com/news/anthropic-acquires-bun-as-claude-code-reaches-usd1b-milestone
59•httpteapot•1h ago•11 comments

Comparing AWS Lambda ARM64 vs. x86_64 Performance Across Runtimes in Late 2025

https://chrisebert.net/comparing-aws-lambda-arm64-vs-x86_64-performance-across-multiple-runtimes-...
111•hasanhaja•10h ago•51 comments

Proximity to coworkers increases long-run development, lowers short-term output (2023)

https://pallais.scholars.harvard.edu/publications/power-proximity-coworkers-training-tomorrow-or-...
154•delichon•5h ago•111 comments