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

Pow() Returns Incorrect Result #394

Open
n3pheddy opened this issue Jan 9, 2025 · 0 comments
Open

Pow() Returns Incorrect Result #394

n3pheddy opened this issue Jan 9, 2025 · 0 comments

Comments

@n3pheddy
Copy link

n3pheddy commented Jan 9, 2025

Pow() returns different values for certain exponents across different releases.

In Go Playground, try the following code:

package main

import (
	"fmt"

	"github.com/shopspring/decimal"
)

func main() {
	x := decimal.NewFromInt(10).Pow(decimal.NewFromInt(-18))
	fmt.Printf("10 to the power of -18 is %s", x)
}
-- go.mod --
module play.ground

require github.com/shopspring/decimal v1.4.0

//require github.com/shopspring/decimal v1.3.1

v1.4.0 returns 0 while v1.3.1 returns 0.000000000000000001

After a bit of testing, it looks like for v1.4.0, with base 10 and any integer exponent <= -17 will return 0
For v1.3.1, with base 10 and any odd integer exponent <= -17 will return 0, while even integer exponents return the correct result.

The expectation is for all negative integer exponents to return the correct result (0.1, 0.001, 0.0001, etc)

Tested on go version go1.23.4 darwin/arm64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant