}
// exp consumed - not needed anymore
- // compute pow5 if needed
- pow5 := z.b.abs
+ // apply exp5 contributions
+ // (start with exp5 so the numbers to multiply are smaller)
if exp5 != 0 {
n := exp5
if n < 0 {
n = -n
}
- pow5 = pow5.expNN(natFive, nat(nil).setWord(Word(n)), nil)
+ pow5 := z.b.abs.expNN(natFive, nat(nil).setWord(Word(n)), nil) // use underlying array of z.b.abs
+ if exp5 > 0 {
+ z.a.abs = z.a.abs.mul(z.a.abs, pow5)
+ z.b.abs = z.b.abs.setWord(1)
+ } else {
+ z.b.abs = pow5
+ }
+ } else {
+ z.b.abs = z.b.abs.setWord(1)
}
- // apply dividend contributions of exponents
- // (start with exp5 so the numbers to multiply are smaller)
- if exp5 > 0 {
- z.a.abs = z.a.abs.mul(z.a.abs, pow5)
- exp5 = 0
- }
+ // apply exp2 contributions
if exp2 > 0 {
if int64(uint(exp2)) != exp2 {
panic("exponent too large")
}
z.a.abs = z.a.abs.shl(z.a.abs, uint(exp2))
- exp2 = 0
- }
-
- // apply divisor contributions of exponents
- z.b.abs = z.b.abs.setWord(1)
- if exp5 < 0 {
- z.b.abs = pow5
- }
- if exp2 < 0 {
+ } else if exp2 < 0 {
if int64(uint(-exp2)) != -exp2 {
panic("exponent too large")
}
}
}
}
+
+func TestIssue31184(t *testing.T) {
+ var x Rat
+ for _, want := range []string{
+ "-213.090",
+ "8.192",
+ "16.000",
+ } {
+ x.SetString(want)
+ got := x.FloatString(3)
+ if got != want {
+ t.Errorf("got %s, want %s", got, want)
+ }
+ }
+}