summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbackend/src/libocl/script/ocl_convert.sh35
1 files changed, 23 insertions, 12 deletions
diff --git a/backend/src/libocl/script/ocl_convert.sh b/backend/src/libocl/script/ocl_convert.sh
index bc02de38..f063f095 100755
--- a/backend/src/libocl/script/ocl_convert.sh
+++ b/backend/src/libocl/script/ocl_convert.sh
@@ -657,23 +657,34 @@ OVERLOADABLE float convert_float_rtn(double x)
long lval = as_long(x);
int exp = ((lval & DF_EXP_MASK) >> DF_EXP_OFFSET) - DF_EXP_BIAS;
int sign = (lval & DF_SIGN_MASK)?1:0;
+ long ma = (lval &DF_MAN_MASK);
- ret = sign;
- ret = (lval & DF_ABS_MASK) ? ret:0;
- tmp = 0x1000000 >> (23 - (exp + 149));
+ int fval = ((exp + 127) << 23) |convert_int(ma >> 29);
+ if((ma & 0x1FFFFFFF) && sign) fval += 1;
+ ret = fval;
+
+ ma |= DF_IMPLICITE_ONE;
+ tmp = ma >> (-exp - 97);
+ long shift = (1UL << (-exp - 97)) -1UL;
+ if((ma & shift) && sign) tmp += 1;
ret = (exp < -126) ? tmp:ret;
- long ma = (lval &DF_MAN_MASK);
- tmp = (lval & DF_MAN_MASK) ? SF_NAN:SF_POSITIVE_INF;
- ret = (exp == 1024) ? tmp:ret;
- tmp = SF_POSITIVE_INF;
+
+ tmp = sign;
+ ret = (exp < -149) ? tmp:ret;
+
+ tmp = sign ? 0x7F800000:0x7F7FFFFF;
ret = (exp > 127) ? tmp:ret;
- ret = (lval & DF_ABS_MASK) ? ret:0;
- tmp = ((exp + 127) << 23) |convert_int(ma >> 29);
- if((ma & 0x1FFFFFFF) && sign) tmp += 1;
- ret = ((exp >= -126) && (exp <= 127)) ? tmp:ret;
+
+ tmp = (lval & DF_MAN_MASK) ? 0x7FFFFFFF:0x7F800000;
+ ret = (exp == 1024) ? tmp:ret;
+
+ tmp = sign ? (0xFF800000) : (0x7F7FFFFF);
+ ret = ((exp == 1023) && (ma == DF_MAN_MASK)) ? tmp:ret;
+
+ ret = ((lval & DF_ABS_MASK) == 0) ? 0:ret;
+
ret |= (sign << 31);
float ftemp = as_float(ret);
-
return ftemp;
}