(strVal string)
| 61 | } |
| 62 | |
| 63 | func makeConstWithPrecision(strVal string) *constWithPrecision { |
| 64 | c := &constWithPrecision{} |
| 65 | if _, _, err := c.unrounded.SetString(strVal); err != nil { |
| 66 | panic(err) |
| 67 | } |
| 68 | // The length of the string might be one higher than the available precision |
| 69 | // (because of the decimal point), but that's ok. |
| 70 | maxPrec := uint32(len(strVal)) |
| 71 | for p := uint32(1); p < maxPrec; p *= 2 { |
| 72 | var d Decimal |
| 73 | |
| 74 | ctx := Context{ |
| 75 | Precision: p, |
| 76 | Rounding: RoundHalfUp, |
| 77 | MaxExponent: MaxExponent, |
| 78 | MinExponent: MinExponent, |
| 79 | } |
| 80 | _, err := ctx.Round(&d, &c.unrounded) |
| 81 | if err != nil { |
| 82 | panic(err) |
| 83 | } |
| 84 | c.vals = append(c.vals, d) |
| 85 | } |
| 86 | return c |
| 87 | } |
| 88 | |
| 89 | // get returns the given constant, rounded down to a precision at least as high |
| 90 | // as the given precision. |
searching dependent graphs…