summaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rwxr-xr-xbackend/src/libocl/script/ocl_convert.sh24
1 files changed, 24 insertions, 0 deletions
diff --git a/backend/src/libocl/script/ocl_convert.sh b/backend/src/libocl/script/ocl_convert.sh
index e7969b76..3061bcc1 100755
--- a/backend/src/libocl/script/ocl_convert.sh
+++ b/backend/src/libocl/script/ocl_convert.sh
@@ -1348,6 +1348,30 @@ OVERLOADABLE double convert_double_rtp(long x)
ret |= (x & DF_SIGN_MASK);
return as_double(ret);
}
+
+OVERLOADABLE double convert_double_rtn(long x)
+{
+ long exp;
+ long ret, ma, tmp;
+ int sign = (x & DF_SIGN_MASK) ? 1:0;
+
+ long absX = abs(x);
+ int msbOne = 64 -clz(absX);
+ exp = msbOne + DF_EXP_BIAS - 1;
+ ret = (exp << 52);
+ int shift = abs(53 - msbOne);
+ tmp = ret | ((absX << shift) &DF_MAN_MASK);
+
+ ma = (absX & ((0x1 << shift) - 1));
+ ret |= (absX >> shift) &DF_MAN_MASK;
+ if(ma && sign) ret += 1;
+
+ ret = (msbOne < 54) ? tmp:ret;
+ ret = (msbOne == 0) ? 0:ret;
+
+ ret |= (x & DF_SIGN_MASK);
+ return as_double(ret);
+}
'
fi