AssignComputeBounds sets f to the floating point value defined by mant, exp and precision given by flt. It returns lower, upper such that any number in the closed interval [lower, upper] is converted back to the same floating point number.
(mant uint64, exp int, neg bool, flt *floatInfo)
| 174 | // lower, upper such that any number in the closed interval |
| 175 | // [lower, upper] is converted back to the same floating point number. |
| 176 | func (f *extFloat) AssignComputeBounds(mant uint64, exp int, neg bool, flt *floatInfo) (lower, upper extFloat) { |
| 177 | f.mant = mant |
| 178 | f.exp = exp - int(flt.mantbits) |
| 179 | f.neg = neg |
| 180 | if f.exp <= 0 && mant == (mant>>uint(-f.exp))<<uint(-f.exp) { |
| 181 | // An exact integer |
| 182 | f.mant >>= uint(-f.exp) |
| 183 | f.exp = 0 |
| 184 | return *f, *f |
| 185 | } |
| 186 | expBiased := exp - flt.bias |
| 187 | |
| 188 | upper = extFloat{mant: 2*f.mant + 1, exp: f.exp - 1, neg: f.neg} |
| 189 | if mant != 1<<flt.mantbits || expBiased == 1 { |
| 190 | lower = extFloat{mant: 2*f.mant - 1, exp: f.exp - 1, neg: f.neg} |
| 191 | } else { |
| 192 | lower = extFloat{mant: 4*f.mant - 1, exp: f.exp - 2, neg: f.neg} |
| 193 | } |
| 194 | return |
| 195 | } |
| 196 | |
| 197 | // Normalize normalizes f so that the highest bit of the mantissa is |
| 198 | // set, and returns the number by which the mantissa was left-shifted. |