Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(osmomath): Exp2 function #3708

Merged
merged 20 commits into from
Dec 16, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions osmomath/exp2.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,14 @@ func Exp2(exponent BigDec) BigDec {
panic(fmt.Sprintf("negative exponent %s is not supported", exponent))
}

integerExponentDec := exponent.TruncateDec()
integerExponent := integerExponentDec.TruncateInt()
integerResult := twoBigDec.PowerInteger(integerExponent.Uint64())
integerExponent := exponent.TruncateDec()

fractionalExponent := exponent.Sub(integerExponentDec)
fractionalExponent := exponent.Sub(integerExponent)
fractionalResult := exp2ChebyshevRationalApprox(fractionalExponent)

result := integerResult.Mul(fractionalResult)
fractionalResult.i = fractionalResult.i.Lsh(fractionalResult.i, uint(integerExponent.TruncateInt().Uint64()))

return result
return fractionalResult
p0mvn marked this conversation as resolved.
Show resolved Hide resolved
}

// exp2ChebyshevRationalApprox takes 2 to the power of a given decimal exponent.
Expand Down