fix Context.Sub ignoring receiver context#94
Open
marcelocantos wants to merge 1 commit intoanz-bank:masterfrom
Open
fix Context.Sub ignoring receiver context#94marcelocantos wants to merge 1 commit intoanz-bank:masterfrom
marcelocantos wants to merge 1 commit intoanz-bank:masterfrom
Conversation
Context.Sub called d.Add() which routes through DefaultContext, silently ignoring the receiver's rounding mode. Changed to ctx.Add() so the caller's context is respected. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
anzboi
approved these changes
Feb 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Context.Subsilently ignores its receiver's rounding mode. It callsd.Add(...), which dispatches throughDefaultContext(HalfUp), rather thanctx.Add(...):Why this matters
Every other context-aware method (
ctx.Add,ctx.Mul,ctx.Quo,ctx.FMA,ctx.Round,ctx.ToIntegral) correctly routes through the receiver.ctx.Subis the sole exception. This means:The bug is currently invisible in tests because:
d.Sub(e)convenience method usesDefaultContext(HalfUp), which happens to match whatctx.Subwas accidentally doing.subtractcallsctx.Add(a, b.Neg())directly, bypassingctx.Subentirely.In practice, it only surfaces when someone explicitly constructs a
Context{Rounding: HalfEven}orContext{Rounding: Down}and calls.Subon it — the rounding mode is silently wrong.Also fixes the doc comment which said
// Addinstead of// Sub.Test plan
go test ./d64— passgo test -tags=decimal_debug ./d64— passd→ctx) that makesSubconsistent with every otherContextmethod. The existing decTest subtract suite validates correctness.🤖 Generated with Claude Code