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
1476•ryanvogel•9h ago•720 comments

IBM CEO says there is 'no way' spending on AI data centers will pay off

https://www.businessinsider.com/ibm-ceo-big-tech-ai-capex-data-center-spending-2025-12
281•nabla9•9h ago•366 comments

Paged Out

https://pagedout.institute
244•varjag•7h ago•29 comments

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

https://snoutcover.com/billie-story
424•ragswag•2d ago•54 comments

Kohler Can Access Pictures from "End-to-End Encrypted" Toilet Camera

https://varlogsimon.leaflet.pub/3m6zrw6k2bs2p?interactionDrawer=quotes
69•TimDotC•1h ago•57 comments

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

https://www.theverge.com/news/836212/openai-code-red-chatgpt
487•goplayoutside•12h ago•571 comments

DOOM could have had PC Speaker Music

https://lenowo.org/viewtopic.php?t=45
43•minki_the_avali•4h ago•32 comments

Amazon launches Trainium3

https://techcrunch.com/2025/12/02/amazon-releases-an-impressive-new-ai-chip-and-teases-a-nvidia-f...
140•thnaks•8h ago•54 comments

Qwen3-VL can scan two-hour videos and pinpoint nearly every detail

https://the-decoder.com/qwen3-vl-can-scan-two-hour-videos-and-pinpoint-nearly-every-detail/
120•thm•2d ago•35 comments

Learning music with Strudel

https://terryds.notion.site/Learning-Music-with-Strudel-2ac98431b24180deb890cc7de667ea92
402•terryds•1w ago•103 comments

Free static site generator for small restaurants and cafes

https://lite.localcafe.org/
95•fullstacking•7h ago•60 comments

All about automotive lidar

https://mainstreetautonomy.com/blog/2025-08-29-all-about-automotive-lidar/
111•dllu•1d ago•56 comments

Zig's new plan for asynchronous programs

https://lwn.net/SubscriberLink/1046084/4c048ee008e1c70e/
228•messe•12h ago•185 comments

School cell phone bans and student achievement

https://www.nber.org/digest/202512/school-cell-phone-bans-and-student-achievement
96•harias•9h ago•97 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...
294•speckx•9h ago•104 comments

Ecosia: The greenest AI is here

https://blog.ecosia.org/ecosia-ai/
69•doener•6h ago•41 comments

Practical Intro to Operational Transformation

https://archive.casouri.cc/note/2025/practical-intro-ot/
20•casouri•6d ago•2 comments

Exploring Large HTML Documents on the Web

https://calendar.perfplanet.com/2025/exploring-large-html-documents-on-the-web/
31•zdw•4h ago•2 comments

Delty (YC X25) Is Hiring

https://www.ycombinator.com/companies/delty/jobs/aPWMaiq-full-stack-software-engineer
1•lalitkundu•6h ago

StutterZero: Speech Conversion for Stuttering Transcription and Correction

https://arxiv.org/abs/2510.18938
8•internetguy•6d ago•2 comments

Load ZX Spectrum – first Museum dedicated to our first personal computer

https://loadzx.com/en/
9•elvis70•6d ago•4 comments

YesNotice

https://infinitedigits.co/docs/software/yesnotice/
156•surprisetalk•1w ago•55 comments

Advent of Compiler Optimisations 2025

https://xania.org/202511/advent-of-compiler-optimisation
347•vismit2000•17h ago•58 comments

Mistral 3 family of models released

https://mistral.ai/news/mistral-3
676•pember•12h ago•193 comments

Addressing the adding situation

https://xania.org/202512/02-adding-integers
248•messe•16h ago•85 comments

Cursed circuits: charge pump voltage halver

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

Python Data Science Handbook

https://jakevdp.github.io/PythonDataScienceHandbook/
224•cl3misch•14h ago•42 comments

A series of vignettes from my childhood and early career

https://www.jasonscheirer.com/weblog/vignettes/
152•absqueued•15h ago•87 comments

Claude 4.5 Opus’ Soul Document

https://www.lesswrong.com/posts/vpNG99GhbBoLov9og/claude-4-5-opus-soul-document
281•the-needful•8h ago•165 comments

AI generated font using Nano Banana

https://constanttime.notion.site/Worlds-first-Ai-generated-font-using-nano-banana-2ba6f8e15af1801...
60•ebaad96•5h ago•23 comments