From d1fec505203b4cc1e4a056d0136d730b07c1949d Mon Sep 17 00:00:00 2001 From: Jake Wang Date: Fri, 18 Sep 2026 21:06:46 -0400 Subject: [PATCH] Fix the scale of the small-input exponential result --- decimal.go | 2 +- decimal_test.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/decimal.go b/decimal.go index ee554d4c..71a28a64 100644 --- a/decimal.go +++ b/decimal.go @@ -998,7 +998,7 @@ func (d Decimal) ExpHullAbrham(overallPrecision uint32) (Decimal, error) { // Return 1 if abs(d) small enough; this also avoids later over/underflow overflowThreshold2 := New(9, -int32(currentPrecision)-1) if d.Abs().Cmp(overflowThreshold2) <= 0 { - return Decimal{oneInt, d.exp}, nil + return Decimal{oneInt, 0}, nil } // t is the smallest integer >= 0 such that the corresponding abs(d/k) < 1 diff --git a/decimal_test.go b/decimal_test.go index 48c1e21d..774ebc38 100644 --- a/decimal_test.go +++ b/decimal_test.go @@ -2953,6 +2953,15 @@ func TestDecimal_ExpHullAbrham(t *testing.T) { OverallPrecision uint32 ExpectedDec string }{ + {"0.000001", 4, "1"}, + {"-0.000001", 4, "1"}, + {"0.00000100", 4, "1"}, + {"-0.00000100", 4, "1"}, + {"0.00009", 4, "1"}, + {"0.000000000001", 8, "1"}, + {"-0.000000000001", 8, "1"}, + {"0.001", 4, "1.001"}, + {"-0.001", 4, "0.999"}, {"0", 1, "1"}, {"0.00", 5, "1"}, {"0.5", 5, "1.6487"},