Skip to content

Commit

Permalink
binary16: set exact to false if mantissa is larger than precision
Browse files Browse the repository at this point in the history
  • Loading branch information
mewmew committed Jul 7, 2018
1 parent 3048931 commit 8f919d9
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions binary16/binary16.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ func NewFromBig(x *big.Float) (f Float, exact bool) {
// Exponent and mantissa.
mant := &big.Float{}
exponent := x.MantExp(mant)
// TODO: Check overflow and set exact.
fmt.Println("exponent:", exponent)
exp := exponent - 1 + bias
// 0b11111
Expand All @@ -111,17 +110,13 @@ func NewFromBig(x *big.Float) (f Float, exact bool) {
mant.SetMantExp(mant, precision)
fmt.Println("mant:", mant)
if !mant.IsInt() {
// TODO: handle truncation.
panic("truncation")
exact = false
}
mantissa, _ := mant.Uint64()
fmt.Println("mantissa:", mantissa)
mantissa &^= 1024 // clear implicit lead bit.
fmt.Println("mantissa:", mantissa)

//m, _ := mant.Rat(nil)
//fmt.Println("m:", m)

// 0b11111111111 (including implicit lead bit)
exact = exact && (mantissa&^0x7FF) == 0
mantissa &= 0x7FF
Expand Down

0 comments on commit 8f919d9

Please sign in to comment.