Home | History | Annotate | Download | only in big

Lines Matching defs:Bits

5 // This file implements the Bits type used for testing Float operations
17 // A Bits value b represents a finite floating-point number x of the form
22 // used to form fractions. A Bits value is normalized if each b[i] occurs at
23 // most once. For instance Bits{0, 0, 1} is not normalized but represents the
24 // same floating-point number as Bits{2}, which is normalized. The zero (nil)
25 // value of Bits is a ready to use Bits value and represents the value 0.
26 type Bits []int
28 func (x Bits) add(y Bits) Bits {
32 func (x Bits) mul(y Bits) Bits {
33 var p Bits
44 x, y, want Bits
47 {Bits{}, Bits{}, nil},
48 {Bits{0}, Bits{0}, Bits{0}},
49 {Bits{0}, Bits{1}, Bits{1}},
50 {Bits{1}, Bits{1, 2, 3}, Bits{2, 3, 4}},
51 {Bits{-1}, Bits{1}, Bits{0}},
52 {Bits{-10, -1, 0, 1, 10}, Bits{1, 2, 3}, Bits{-9, -8, -7, 0, 1, 2, 1, 2, 3, 2, 3, 4, 11, 12, 13}},
63 // norm returns the normalized bits for x: It removes multiple equal entries
64 // by treating them as an addition (e.g., Bits{5, 5} => Bits{6}), and it sorts
66 func (x Bits) norm() Bits {
75 var z Bits
87 x, want Bits
90 {Bits{}, Bits{}},
91 {Bits{0}, Bits{0}},
92 {Bits{0, 0}, Bits{1}},
93 {Bits{3, 1, 1}, Bits{2, 3}},
94 {Bits{10, 9, 8, 7, 6, 6}, Bits{11}},
106 // to prec bits according to mode.
107 func (x Bits) round(prec uint, mode RoundingMode) *Float {
126 // determine bit 0, rounding, and sticky bit, and result bits z
128 var z Bits
153 f.Add(f, Bits{int(r) + 1}.Float())
159 // z = sum(2**bits[i]), with i = range bits. If multiple bits[i] are equal,
160 // they are added: Bits{0, 1, 0}.Float() == 2**0 + 2**1 + 2**0 = 4.
161 func (bits Bits) Float() *Float {
163 if len(bits) == 0 {
166 // len(bits) > 0
170 for i, b := range bits {
178 for _, b := range bits {
201 bits Bits
206 {Bits{0}, "0x.8p+1"},
207 {Bits{1}, "0x.8p+2"},
208 {Bits{-1}, "0x.8p+0"},
209 {Bits{63}, "0x.8p+64"},
210 {Bits{33, -30}, "0x.8000000000000001p+34"},
211 {Bits{255, 0}, "0x.8000000000000000000000000000000000000000000000000000000000000001p+256"},
214 {Bits{0, 0}, "0x.8p+2"},
215 {Bits{0, 0, 0, 0}, "0x.8p+3"},
216 {Bits{0, 1, 0}, "0x.8p+3"},
217 {append(Bits{2, 1, 0} /* 7 */, Bits{3, 1} /* 10 */ ...), "0x.88p+5" /* 17 */},
219 f := test.bits.Float()
221 t.Errorf("setBits(%v) = %s; want %s", test.bits, got, test.want)