case FC_NAN:
val_buffer = (fp_value*) alloca(calc_buffer_size);
fc_get_qnan(&int_float->desc, val_buffer);
case FC_NAN:
val_buffer = (fp_value*) alloca(calc_buffer_size);
fc_get_qnan(&int_float->desc, val_buffer);
/* mantissa all zeros, so zero exponent (because of explicit one) */
if (hsb == ROUNDING_BITS + in_val->desc.mantissa_size) {
/* mantissa all zeros, so zero exponent (because of explicit one) */
if (hsb == ROUNDING_BITS + in_val->desc.mantissa_size) {
/* denormalized means exponent of zero */
sc_val_from_ulong(0, _exp(out_val));
/* denormalized means exponent of zero */
sc_val_from_ulong(0, _exp(out_val));
/* check for rounding overflow */
hsb = ROUNDING_BITS + out_val->desc.mantissa_size - sc_get_highest_set_bit(_mant(out_val)) - 1;
/* check for rounding overflow */
hsb = ROUNDING_BITS + out_val->desc.mantissa_size - sc_get_highest_set_bit(_mant(out_val)) - 1;
sc_val_from_ulong(1, temp);
_shift_right(_mant(out_val), temp, _mant(out_val));
if (exact && sc_had_carry())
exact = 0;
sc_add(_exp(out_val), temp, _exp(out_val));
sc_val_from_ulong(1, temp);
_shift_right(_mant(out_val), temp, _mant(out_val));
if (exact && sc_had_carry())
exact = 0;
sc_add(_exp(out_val), temp, _exp(out_val));
/* overflow caused the mantissa to be normal again,
* so adapt the exponent accordingly */
sc_val_from_ulong(1, temp);
sc_add(_exp(out_val), temp, _exp(out_val));
/* overflow caused the mantissa to be normal again,
* so adapt the exponent accordingly */
sc_val_from_ulong(1, temp);
sc_add(_exp(out_val), temp, _exp(out_val));
}
/* no further rounding is needed, because rounding overflow means
* the carry of the original rounding was propagated all the way
}
/* no further rounding is needed, because rounding overflow means
* the carry of the original rounding was propagated all the way
/* shift the smaller value to the right to align the radix point */
/* subnormals have their radix point shifted to the right,
* take care of this first */
/* shift the smaller value to the right to align the radix point */
/* subnormals have their radix point shifted to the right,
* take care of this first */
sc_val_from_ulong(1, temp);
sc_sub(exp_diff, temp, exp_diff);
}
sc_val_from_ulong(1, temp);
sc_sub(exp_diff, temp, exp_diff);
}
/* _normalize expects a 'normal' radix point, adding two subnormals
* results in a subnormal radix point -> shifting before normalizing */
/* _normalize expects a 'normal' radix point, adding two subnormals
* results in a subnormal radix point -> shifting before normalizing */
sc_val_from_ulong(1, NULL);
_shift_left(_mant(result), sc_get_buffer(), _mant(result));
}
sc_val_from_ulong(1, NULL);
_shift_left(_mant(result), sc_get_buffer(), _mant(result));
}
sc_sub(_exp(result), temp, _exp(result));
/* mixed normal, subnormal values introduce an error of 1, correct it */
sc_sub(_exp(result), temp, _exp(result));
/* mixed normal, subnormal values introduce an error of 1, correct it */
sc_val_from_ulong(1, temp);
sc_add(_exp(result), temp, _exp(result));
}
sc_val_from_ulong(1, temp);
sc_add(_exp(result), temp, _exp(result));
}
sc_val_from_ulong(0, NULL);
_save_result(_exp(result));
_save_result(_mant(result));
sc_val_from_ulong(0, NULL);
_save_result(_exp(result));
_save_result(_mant(result));
sc_add(_exp(result), temp, _exp(result));
/* mixed normal, subnormal values introduce an error of 1, correct it */
sc_add(_exp(result), temp, _exp(result));
/* mixed normal, subnormal values introduce an error of 1, correct it */
sc_val_from_ulong(1, temp);
sc_add(_exp(result), temp, _exp(result));
}
sc_val_from_ulong(1, temp);
sc_add(_exp(result), temp, _exp(result));
}
sc_val_from_ulong(0, NULL);
_save_result(_exp(result));
_save_result(_mant(result));
sc_val_from_ulong(0, NULL);
_save_result(_exp(result));
_save_result(_mant(result));
-void *fc_val_from_str(const char *str, size_t len, const ieee_descriptor_t *desc, void *result)
+void *fc_val_from_str(const char *str, size_t len,
+ const ieee_descriptor_t *desc, void *result)
tmp_desc.exponent_size = 15;
tmp_desc.mantissa_size = 63;
tmp_desc.explicit_one = 1;
tmp_desc.exponent_size = 15;
tmp_desc.mantissa_size = 63;
tmp_desc.explicit_one = 1;
fc_val_from_ieee754(val, &tmp_desc, tmp);
return fc_cast(tmp, desc, (fp_value*) result);
}
fc_val_from_ieee754(val, &tmp_desc, tmp);
return fc_cast(tmp, desc, (fp_value*) result);
}
temp = (char*) alloca(value_size);
/* CLEAR the buffer, else some bits might be uninitialized */
memset(result, 0, fc_get_buffer_length());
temp = (char*) alloca(value_size);
/* CLEAR the buffer, else some bits might be uninitialized */
memset(result, 0, fc_get_buffer_length());
result->sign = sign;
/* sign and flag suffice to identify NaN or inf, no exponent/mantissa
* encoding is needed. the function can return immediately in these cases */
if (my_isnan(l)) {
result->sign = sign;
/* sign and flag suffice to identify NaN or inf, no exponent/mantissa
* encoding is needed. the function can return immediately in these cases */
if (my_isnan(l)) {
if (sc_get_highest_set_bit(_mant(value)) == value->desc.mantissa_size + 1)
return fc_get_qnan(desc, result);
else
return fc_get_snan(desc, result);
}
if (sc_get_highest_set_bit(_mant(value)) == value->desc.mantissa_size + 1)
return fc_get_qnan(desc, result);
else
return fc_get_snan(desc, result);
}
- result->desc.exponent_size = desc->exponent_size;
- result->desc.mantissa_size = desc->mantissa_size;
- result->desc.explicit_one = desc->explicit_one;
- result->desc.clss = value->desc.clss;
-
+ result->desc = *desc;
+ result->clss = value->clss;
sc_add(_exp(value), temp, _exp(result));
/* _normalize expects normalized radix point */
sc_add(_exp(value), temp, _exp(result));
/* _normalize expects normalized radix point */
sc_val_from_ulong(1, NULL);
_shift_left(_mant(value), sc_get_buffer(), _mant(result));
} else if (value != result) {
sc_val_from_ulong(1, NULL);
_shift_left(_mant(value), sc_get_buffer(), _mant(result));
} else if (value != result) {
- result->desc.exponent_size = desc->exponent_size;
- result->desc.mantissa_size = desc->mantissa_size;
- result->desc.explicit_one = desc->explicit_one;
- result->desc.clss = FC_NORMAL;
-
+ result->desc = *desc;
+ result->clss = FC_NORMAL;
}
char *fc_print(const fp_value *val, char *buf, int buflen, unsigned base)
}
char *fc_print(const fp_value *val, char *buf, int buflen, unsigned base)
case FC_INF:
snprintf(buf, buflen, "%cINF", val->sign ? '-' : '+');
break;
case FC_INF:
snprintf(buf, buflen, "%cINF", val->sign ? '-' : '+');
break;
case FC_INF:
snprintf(buf, buflen, "%cINF", val->sign ? '-' : '+');
break;
case FC_INF:
snprintf(buf, buflen, "%cINF", val->sign ? '-' : '+');
break;
int exp_bias = (1 << (a->desc.exponent_size - 1)) - 1;
int exp_val = sc_val_to_long(_exp(a)) - exp_bias;
int shift, highest;
int exp_bias = (1 << (a->desc.exponent_size - 1)) - 1;
int exp_val = sc_val_to_long(_exp(a)) - exp_bias;
int shift, highest;