Open guotie opened 4 months ago
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?
code:
result:
why?