summaryrefslogtreecommitdiffstats
path: root/mathfuncs_convert.h
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@gmail.com>2012-11-30 18:35:55 -0500
committerErik Schnetter <schnetter@gmail.com>2012-11-30 18:35:55 -0500
commit058c31f56befa0b0a9935d5a1a9f904cf6c39afc (patch)
tree94c26bc0a3cd3ab9e436dff57fc49e0c5c8363bd /mathfuncs_convert.h
parentd2614759a1d542c41af59b04d8711246d2a1e876 (diff)
downloadvecmathlib-058c31f56befa0b0a9935d5a1a9f904cf6c39afc.zip
vecmathlib-058c31f56befa0b0a9935d5a1a9f904cf6c39afc.tar.gz
Correct sqrt and convert_*
Diffstat (limited to 'mathfuncs_convert.h')
-rw-r--r--mathfuncs_convert.h15
1 files changed, 9 insertions, 6 deletions
diff --git a/mathfuncs_convert.h b/mathfuncs_convert.h
index 4dfffef..19f7025 100644
--- a/mathfuncs_convert.h
+++ b/mathfuncs_convert.h
@@ -24,21 +24,24 @@ namespace vecmathlib {
// Convert lower bits
intvec_t xlo = x & IV((U(1) << lobits) - 1);
// exponent for the equivalent floating point number
- int_t exponent_lo = FP::exponent_offset + lobits;
+ int_t exponent_lo = (FP::exponent_offset + lobits) << FP::mantissa_bits;
xlo |= exponent_lo;
// subtract hidden mantissa bit
realvec_t flo = as_float(xlo) - RV(FP::as_float(exponent_lo));
// Convert upper bits
// make unsigned by subtracting largest negative number
+ // (only do this for the high bits, since they have sufficient
+ // precision to handle the overflow)
x ^= FP::sign_mask;
intvec_t xhi = lsr(x, lobits);
// exponent for the equivalent floating point number
- int_t exponent_hi = FP::exponent_offset + FP::bits;
+ int_t exponent_hi = (FP::exponent_offset + 2*lobits) << FP::mantissa_bits;
xhi |= exponent_hi;
- // add largest negative number, and subtract hidden mantissa bit
- realvec_t
- fhi = as_float(xhi) - RV(FP::as_float(exponent_hi) + R(FP::sign_mask));
+ // subtract hidden mantissa bit
+ realvec_t fhi = as_float(xhi) - RV(FP::as_float(exponent_hi));
+ // add largest negative number again
+ fhi -= RV(R(FP::sign_mask));
// Combine results
return flo + fhi;
@@ -76,7 +79,7 @@ namespace vecmathlib {
// Handle negative numbers
ix = ifthen(is_negative, -ix, ix);
// Handle zero
- ix = ifthen(is_zero, IV(0), ix);
+ ix = ifthen(is_zero, IV(I(0)), ix);
return ix;
}
OpenPOWER on IntegriCloud