MCPcopy
hub / github.com/shopspring/decimal / powBigIntWithPrecision

Method powBigIntWithPrecision

decimal.go:916–946  ·  view source on GitHub ↗
(exp *big.Int, precision int32)

Source from the content-addressed store, hash-verified

914}
915
916func (d Decimal) powBigIntWithPrecision(exp *big.Int, precision int32) (Decimal, error) {
917 if d.IsZero() && exp.Sign() == 0 {
918 return Decimal{}, fmt.Errorf("cannot represent undefined value of 0**0")
919 }
920
921 tmpExp := new(big.Int).Set(exp)
922 isExpNeg := exp.Sign() < 0
923
924 if isExpNeg {
925 tmpExp.Abs(tmpExp)
926 }
927
928 n, result := d, New(1, 0)
929
930 for tmpExp.Sign() > 0 {
931 if tmpExp.Bit(0) == 1 {
932 result = result.Mul(n)
933 }
934 tmpExp.Rsh(tmpExp, 1)
935
936 if tmpExp.Sign() > 0 {
937 n = n.Mul(n)
938 }
939 }
940
941 if isExpNeg {
942 return New(1, 0).DivRound(result, precision), nil
943 }
944
945 return result, nil
946}
947
948// ExpHullAbrham calculates the natural exponent of decimal (e to the power of d) using Hull-Abraham algorithm.
949// OverallPrecision argument specifies the overall precision of the result (integer part + decimal part).

Callers 2

PowWithPrecisionMethod · 0.95
PowBigIntMethod · 0.95

Calls 6

IsZeroMethod · 0.95
NewFunction · 0.85
SignMethod · 0.80
AbsMethod · 0.80
MulMethod · 0.80
DivRoundMethod · 0.80

Tested by

no test coverage detected