@@ -105,32 +105,59 @@ func (ctx Rounding) round(significand uint64, rndStatus discardedDigit) uint64 {
105
105
return significand
106
106
}
107
107
108
- func signalNaN64 () {
109
- panic ("sNaN64" )
110
- }
111
-
112
- var small64s = [... ]Decimal64 {
113
- new64FromInt64 (- 10 ),
114
- new64FromInt64 (- 9 ),
115
- new64FromInt64 (- 8 ),
116
- new64FromInt64 (- 7 ),
117
- new64FromInt64 (- 6 ),
118
- new64FromInt64 (- 5 ),
119
- new64FromInt64 (- 4 ),
120
- new64FromInt64 (- 3 ),
121
- new64FromInt64 (- 2 ),
122
- NegOne64 ,
123
- Zero64 ,
124
- One64 ,
125
- new64FromInt64 (2 ),
126
- new64FromInt64 (3 ),
127
- new64FromInt64 (4 ),
128
- new64FromInt64 (5 ),
129
- new64FromInt64 (6 ),
130
- new64FromInt64 (7 ),
131
- new64FromInt64 (8 ),
132
- new64FromInt64 (9 ),
133
- new64FromInt64 (10 ),
108
+ var ErrNaN64 error = Error ("sNaN64" )
109
+
110
+ 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 ),
122
+
123
+ // 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" ,
134
161
}
135
162
136
163
// New64FromInt64 returns a new Decimal64 with the given value.
@@ -262,10 +289,12 @@ func (d Decimal64) parts() (fl flavor, sign int, exp int, significand uint64) {
262
289
fl = flInf
263
290
case 2 :
264
291
fl = flQNaN
265
- significand = d .bits & (1 << 53 - 1 )
292
+ significand = d .bits & (1 << 51 - 1 )
293
+ return
266
294
case 3 :
267
295
fl = flSNaN
268
- significand = d .bits & (1 << 53 - 1 )
296
+ significand = d .bits & (1 << 51 - 1 )
297
+ return
269
298
}
270
299
case 12 , 13 , 14 :
271
300
// s 11EEeeeeeeee (100)t tttttttttt tttttttttt tttttttttt tttttttttt tttttttttt
@@ -336,8 +365,7 @@ func (d Decimal64) Float64() float64 {
336
365
case flQNaN :
337
366
return math .NaN ()
338
367
}
339
- signalNaN64 ()
340
- return 0
368
+ panic (ErrNaN64 )
341
369
}
342
370
343
371
// Int64 returns an int64 representation of d, clamped to [[math.MinInt64], [math.MaxInt64]].
@@ -360,8 +388,7 @@ func (d Decimal64) Int64x() (i int64, exact bool) {
360
388
case flQNaN :
361
389
return 0 , false
362
390
case flSNaN :
363
- signalNaN64 ()
364
- return 0 , false
391
+ panic (ErrNaN64 )
365
392
}
366
393
exp , whole , frac := expWholeFrac (exp , significand )
367
394
for exp > 0 && whole < math .MaxInt64 / 10 {
@@ -518,20 +545,15 @@ func (d Decimal64) Class() string {
518
545
return "NaN"
519
546
}
520
547
521
- sign := "+"
522
- if dp .sign == 1 {
523
- sign = "-"
524
- }
525
-
526
548
switch {
527
549
case dp .isInf ():
528
- return sign + " Infinity"
550
+ return "+ Infinity-Infinity" [ 9 * dp . sign : 9 * ( dp . sign + 1 )]
529
551
case dp .isZero ():
530
- return sign + " Zero"
552
+ return "+ Zero-Zero" [ 5 * dp . sign : 5 * ( dp . sign + 1 )]
531
553
case dp .isSubnormal ():
532
- return sign + " Subnormal"
554
+ return "+ Subnormal-Subnormal" [ 10 * dp . sign : 10 * ( dp . sign + 1 )]
533
555
}
534
- return sign + " Normal"
556
+ return "+ Normal-Normal" [ 7 * dp . sign : 7 * ( dp . sign + 1 )]
535
557
}
536
558
537
559
// numDecimalDigits returns the magnitude (number of digits) of a uint64.
0 commit comments