summaryrefslogtreecommitdiffhomepage
path: root/ir/tv
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2014-12-30 09:30:34 +0100
committerMatthias Braun <matze@braunis.de>2014-12-30 11:09:08 +0100
commitbdbdf62bc5192f9672c0d5ab83d1a760be980cec (patch)
treea67a9dfe43ec217c2172843221cf301616bdb2ea /ir/tv
parenta57b8f66bf58476b73b8ea5d8701dc82ff21f7d6 (diff)
fltcalc: fix some NaN handling bugs.
Diffstat (limited to 'ir/tv')
-rw-r--r--ir/tv/fltcalc.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/ir/tv/fltcalc.c b/ir/tv/fltcalc.c
index 855c615..3e3bb3c 100644
--- a/ir/tv/fltcalc.c
+++ b/ir/tv/fltcalc.c
@@ -292,11 +292,6 @@ return_nan_b:
*/
static void _fadd(const fp_value *a, const fp_value *b, fp_value *result)
{
- fc_exact = true;
-
- if (handle_NAN(a, b, result))
- return;
-
/* make sure result has a descriptor */
if (result != a && result != b)
result->desc = a->desc;
@@ -1126,6 +1121,10 @@ fp_value *fc_add(const fp_value *a, const fp_value *b, fp_value *result)
if (result == NULL)
result = calc_buffer;
+ fc_exact = true;
+ if (handle_NAN(a, b, result))
+ return result;
+
/* make the value with the bigger exponent the first one */
if (sc_comp(_exp(a), _exp(b)) == ir_relation_less)
_fadd(b, a, result);
@@ -1140,6 +1139,10 @@ fp_value *fc_sub(const fp_value *a, const fp_value *b, fp_value *result)
if (result == NULL)
result = calc_buffer;
+ fc_exact = true;
+ if (handle_NAN(a, b, result))
+ return result;
+
fp_value *temp = (fp_value*) alloca(calc_buffer_size);
memcpy(temp, b, calc_buffer_size);
temp->sign = !b->sign;
@@ -1176,7 +1179,8 @@ fp_value *fc_neg(const fp_value *a, fp_value *result)
if (a != result)
memcpy(result, a, calc_buffer_size);
- result->sign = !a->sign;
+ if (result->clss != FC_NAN)
+ result->sign = !a->sign;
return result;
}