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

result Not accurate #377

Open
guotie opened this issue Jul 8, 2024 · 0 comments
Open

result Not accurate #377

guotie opened this issue Jul 8, 2024 · 0 comments

Comments

@guotie
Copy link

guotie commented Jul 8, 2024

code:

func TestDecimalPow(t *testing.T) {
	d := decimal.NewFromInt(100)
	sqrt := d.Pow(decimal.NewFromFloat(0.5))
	t.Logf("sqrt: %v", sqrt) // 10

	d = decimal.NewFromBigInt(big.NewInt(100), 0)
	sqrt = d.Pow(decimal.NewFromFloat(0.5))
	t.Logf("sqrt: %v", sqrt) // 10

	d = decimal.NewFromBigInt(big.NewInt(10000), 0)
	d = d.Div(decimal.NewFromBigInt(big.NewInt(100), 0))
	sqrt = d.Pow(decimal.NewFromFloat(0.5))
	t.Logf("sqrt: %v", sqrt) // 9.99999999999999999999999999999999999999998
}

result:

sqrt: 10
sqrt: 10
sqrt: 9.99999999999999999999999999999999999999998

why?

@guotie guotie changed the title result Not accurate for Pow(0.5) result Not accurate Jul 8, 2024
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