4
4
"fmt"
5
5
"math"
6
6
"math/bits"
7
+ "strconv"
7
8
)
8
9
9
10
type discardedDigit int
@@ -108,58 +109,42 @@ func (ctx Rounding) round(significand uint64, rndStatus discardedDigit) uint64 {
108
109
var ErrNaN64 error = Error ("sNaN64" )
109
110
110
111
var small64s = []Decimal64 {
111
- newFromPartsRaw (1 , - 14 , 1 * decimal64Base ),
112
-
113
- newFromPartsRaw (1 , - 15 , 9 * decimal64Base ),
114
- newFromPartsRaw (1 , - 15 , 8 * decimal64Base ),
115
- newFromPartsRaw (1 , - 15 , 7 * decimal64Base ),
116
- newFromPartsRaw (1 , - 15 , 6 * decimal64Base ),
117
- newFromPartsRaw (1 , - 15 , 5 * decimal64Base ),
118
- newFromPartsRaw (1 , - 15 , 4 * decimal64Base ),
119
- newFromPartsRaw (1 , - 15 , 3 * decimal64Base ),
120
- newFromPartsRaw (1 , - 15 , 2 * decimal64Base ),
121
- newFromPartsRaw (1 , - 15 , 1 * decimal64Base ),
112
+ new64str ( newFromPartsRaw (1 , - 14 , 1 * decimal64Base ). bits , "-10" ),
113
+
114
+ new64str ( newFromPartsRaw (1 , - 15 , 9 * decimal64Base ). bits , "-9" ),
115
+ new64str ( newFromPartsRaw (1 , - 15 , 8 * decimal64Base ). bits , "-8" ),
116
+ new64str ( newFromPartsRaw (1 , - 15 , 7 * decimal64Base ). bits , "-7" ),
117
+ new64str ( newFromPartsRaw (1 , - 15 , 6 * decimal64Base ). bits , "-6" ),
118
+ new64str ( newFromPartsRaw (1 , - 15 , 5 * decimal64Base ). bits , "-5" ),
119
+ new64str ( newFromPartsRaw (1 , - 15 , 4 * decimal64Base ). bits , "-4" ),
120
+ new64str ( newFromPartsRaw (1 , - 15 , 3 * decimal64Base ). bits , "-3" ),
121
+ new64str ( newFromPartsRaw (1 , - 15 , 2 * decimal64Base ). bits , "-2" ),
122
+ new64str ( newFromPartsRaw (1 , - 15 , 1 * decimal64Base ). bits , "-1" ),
122
123
123
124
// TODO: Decimal64{}?
124
- newFromPartsRaw (0 , 0 , 0 ),
125
-
126
- newFromPartsRaw (0 , - 15 , 1 * decimal64Base ),
127
- newFromPartsRaw (0 , - 15 , 2 * decimal64Base ),
128
- newFromPartsRaw (0 , - 15 , 3 * decimal64Base ),
129
- newFromPartsRaw (0 , - 15 , 4 * decimal64Base ),
130
- newFromPartsRaw (0 , - 15 , 5 * decimal64Base ),
131
- newFromPartsRaw (0 , - 15 , 6 * decimal64Base ),
132
- newFromPartsRaw (0 , - 15 , 7 * decimal64Base ),
133
- newFromPartsRaw (0 , - 15 , 8 * decimal64Base ),
134
- newFromPartsRaw (0 , - 15 , 9 * decimal64Base ),
135
-
136
- newFromPartsRaw (0 , - 14 , 1 * decimal64Base ),
137
- }
138
-
139
- var small64Strings = map [Decimal64 ]string {
140
- small64s [0 ]: "-10" ,
141
- small64s [1 ]: "-9" ,
142
- small64s [2 ]: "-8" ,
143
- small64s [3 ]: "-7" ,
144
- small64s [4 ]: "-6" ,
145
- small64s [5 ]: "-5" ,
146
- small64s [6 ]: "-4" ,
147
- small64s [7 ]: "-3" ,
148
- small64s [8 ]: "-2" ,
149
- small64s [9 ]: "-1" ,
150
- small64s [10 ]: "0" ,
151
- small64s [11 ]: "1" ,
152
- small64s [12 ]: "2" ,
153
- small64s [13 ]: "3" ,
154
- small64s [14 ]: "4" ,
155
- small64s [15 ]: "5" ,
156
- small64s [16 ]: "6" ,
157
- small64s [17 ]: "7" ,
158
- small64s [18 ]: "8" ,
159
- small64s [19 ]: "9" ,
160
- small64s [20 ]: "10" ,
125
+ new64str (newFromPartsRaw (0 , 0 , 0 ).bits , "0" ),
126
+
127
+ new64str (newFromPartsRaw (0 , - 15 , 1 * decimal64Base ).bits , "1" ),
128
+ new64str (newFromPartsRaw (0 , - 15 , 2 * decimal64Base ).bits , "2" ),
129
+ new64str (newFromPartsRaw (0 , - 15 , 3 * decimal64Base ).bits , "3" ),
130
+ new64str (newFromPartsRaw (0 , - 15 , 4 * decimal64Base ).bits , "4" ),
131
+ new64str (newFromPartsRaw (0 , - 15 , 5 * decimal64Base ).bits , "5" ),
132
+ new64str (newFromPartsRaw (0 , - 15 , 6 * decimal64Base ).bits , "6" ),
133
+ new64str (newFromPartsRaw (0 , - 15 , 7 * decimal64Base ).bits , "7" ),
134
+ new64str (newFromPartsRaw (0 , - 15 , 8 * decimal64Base ).bits , "8" ),
135
+ new64str (newFromPartsRaw (0 , - 15 , 9 * decimal64Base ).bits , "9" ),
136
+
137
+ new64str (newFromPartsRaw (0 , - 14 , 1 * decimal64Base ).bits , "10" ),
161
138
}
162
139
140
+ var small64Strings = func () map [uint64 ]string {
141
+ m := make (map [uint64 ]string , len (small64s ))
142
+ for i := - 10 ; i <= 10 ; i ++ {
143
+ m [small64s [10 + i ].bits ] = strconv .Itoa (i )
144
+ }
145
+ return m
146
+ }()
147
+
163
148
// New64FromInt64 returns a new Decimal64 with the given value.
164
149
func New64FromInt64 (i int64 ) Decimal64 {
165
150
if i >= - 10 && i <= 10 {
@@ -258,10 +243,6 @@ func countTrailingZeros(n uint64) int {
258
243
return zeros
259
244
}
260
245
261
- func new64Raw (bits uint64 ) Decimal64 {
262
- return Decimal64 {bits : bits }
263
- }
264
-
265
246
func newFromParts (sign int , exp int , significand uint64 ) Decimal64 {
266
247
return new64 (newFromPartsRaw (sign , exp , significand ).bits )
267
248
}
@@ -272,12 +253,12 @@ func newFromPartsRaw(sign int, exp int, significand uint64) Decimal64 {
272
253
if significand < 0x8 << 50 {
273
254
// s EEeeeeeeee (0)ttt tttttttttt tttttttttt tttttttttt tttttttttt tttttttttt
274
255
// EE ∈ {00, 01, 10}
275
- return new64Raw ( s | uint64 (exp + expOffset )<< (63 - 10 ) | significand )
256
+ return Decimal64 { bits : s | uint64 (exp + expOffset )<< (63 - 10 ) | significand }
276
257
}
277
258
// s 11EEeeeeeeee (100)t tttttttttt tttttttttt tttttttttt tttttttttt tttttttttt
278
259
// EE ∈ {00, 01, 10}
279
260
significand &= 0x8 << 50 - 1
280
- return new64Raw ( s | uint64 (0xc00 | (exp + expOffset ))<< (63 - 12 ) | significand )
261
+ return Decimal64 { bits : s | uint64 (0xc00 | (exp + expOffset ))<< (63 - 12 ) | significand }
281
262
}
282
263
283
264
func (d Decimal64 ) parts () (fl flavor , sign int , exp int , significand uint64 ) {
0 commit comments