uvneginf = 0xFFF0000000000000
mask = 0x7FF
shift = 64 - 11 - 1
- bias = 1022
+ bias = 1023
)
// Inf returns positive infinity if sign >= 0, negative infinity if sign < 0.
MULSD X1, X0
ADDSD $1.0, X0
// return fr * 2**exponent
- MOVL $0x3FF, AX // bias + 1
+ MOVL $0x3FF, AX // bias
ADDL AX, BX
JLE underflow
CMPL BX, $0x7FF
return f, 0
}
x := Float64bits(f)
- exp = int((x>>shift)&mask) - bias
+ exp = int((x>>shift)&mask) - bias + 1
x &^= mask << shift
- x |= bias << shift
+ x |= (-1 + bias) << shift
frac = Float64frombits(x)
return
}
case x != x: // IsNaN(x):
return x
}
- return float64(int((Float64bits(x)>>shift)&mask) - (bias + 1))
+ return float64(int((Float64bits(x)>>shift)&mask) - bias)
}
// Ilogb(x) returns the binary exponent of non-zero x as an integer.
case x < -MaxFloat64 || x > MaxFloat64: // IsInf(x, 0):
return MaxInt32
}
- return int((Float64bits(x)>>shift)&mask) - (bias + 1)
+ return int((Float64bits(x)>>shift)&mask) - bias
}
x := Float64bits(f)
e := uint(x>>shift)&mask - bias
- // Keep the top 11+e bits, the integer part; clear the rest.
- if e < 64-11 {
- x &^= 1<<(64-11-e) - 1
+ // Keep the top 12+e bits, the integer part; clear the rest.
+ if e < 64-12 {
+ x &^= 1<<(64-12-e) - 1
}
int = Float64frombits(x)
frac = f - int
}
exp++
}
- exp -= bias + 1 // unbias exponent
+ exp -= bias // unbias exponent
ix &^= mask << shift
ix |= 1 << shift
if exp&1 == 1 { // odd exp, double x to make it even
if ix != 0 { // remainder, result not exact
q += q & 1 // round according to extra bit
}
- ix = q>>1 + uint64(exp+bias)<<shift // significand + biased exponent
+ ix = q>>1 + uint64(exp-1+bias)<<shift // significand + biased exponent
return Float64frombits(ix)
}