cleaned up a bit
renamed _add to _fadd and _mul to _fmul
add some comments
[r6253]
-
-/********
- * globals
- ********/
+/**
+ * possible float states
+ */
- NORMAL,
- ZERO,
- SUBNORMAL,
- INF,
- NAN,
+ NORMAL, /**< normal representation, implicit 1 */
+ ZERO, /**< +/-0 */
+ SUBNORMAL, /**< denormals, implicit 0 */
+ INF, /**< +/-oo */
+ NAN, /**< Not A Number */
+/** A descriptor for an IEEE float value. */
- char exponent_size;
- char mantissa_size;
- value_class_t class;
+ unsigned char exponent_size; /**< size of exponent in bits */
+ unsigned char mantissa_size; /**< size of mantissa in bits */
+ value_class_t clss; /**< state of this float */
} descriptor_t;
#define CLEAR_BUFFER(buffer) memset(buffer, 0, calc_buffer_size)
} descriptor_t;
#define CLEAR_BUFFER(buffer) memset(buffer, 0, calc_buffer_size)
#define _shift_right(x, y, b) sc_shr((x), (y), value_size*4, 0, (b))
#define _shift_left(x, y, b) sc_shl((x), (y), value_size*4, 0, (b))
#define _shift_right(x, y, b) sc_shr((x), (y), value_size*4, 0, (b))
#define _shift_left(x, y, b) sc_shl((x), (y), value_size*4, 0, (b))
-#define FC_DEFINE1(code) char* fc_##code(const void *a, void *result) \
- { \
- return _calc((const char*)a, NULL, FC_##code, (char*)result); \
- }
+#define FC_DEFINE1(code) \
+char *fc_##code(const void *a, void *result) { \
+ return _calc((const char*)a, NULL, FC_##code, (char*)result); \
+}
-#define FC_DEFINE2(code) char* fc_##code(const void *a, const void *b, void *result) \
- { \
- return _calc((const char*)a, (const char*)b, FC_##code, (char*)result); \
- }
+#define FC_DEFINE2(code) \
+char *fc_##code(const void *a, const void *b, void *result) { \
+ return _calc((const char*)a, (const char*)b, FC_##code, (char*)result); \
+}
#define FUNC_PTR(code) fc_##code
#define FUNC_PTR(code) fc_##code
+/** pack machine-like */
static char* _pack(const char *int_float, char *packed)
{
char *shift_val;
static char* _pack(const char *int_float, char *packed)
{
char *shift_val;
temp = alloca(value_size);
shift_val = alloca(value_size);
temp = alloca(value_size);
shift_val = alloca(value_size);
- switch (_desc(int_float).class) {
+ switch (_desc(int_float).clss) {
case NAN:
val_buffer = alloca(calc_buffer_size);
fc_get_qnan(_desc(int_float).exponent_size, _desc(int_float).mantissa_size, val_buffer);
case NAN:
val_buffer = alloca(calc_buffer_size);
fc_get_qnan(_desc(int_float).exponent_size, _desc(int_float).mantissa_size, val_buffer);
memcpy(&_desc(out_val), &_desc(in_val), sizeof(descriptor_t));
}
memcpy(&_desc(out_val), &_desc(in_val), sizeof(descriptor_t));
}
- _desc(out_val).class = NORMAL;
+ _desc(out_val).clss = NORMAL;
/* mantissa all zeros, so zero exponent (because of explicit one)*/
if (hsb == 2 + _desc(in_val).mantissa_size)
/* mantissa all zeros, so zero exponent (because of explicit one)*/
if (hsb == 2 + _desc(in_val).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));
- _desc(out_val).class = SUBNORMAL;
+ _desc(out_val).clss = SUBNORMAL;
}
/* perform rounding by adding a value that clears the guard bit and the round bit
}
/* perform rounding by adding a value that clears the guard bit and the round bit
}
/* could have rounded down to zero */
}
/* could have rounded down to zero */
- if (sc_is_zero(_mant(out_val)) && (_desc(out_val).class == SUBNORMAL))
- _desc(out_val).class = ZERO;
+ if (sc_is_zero(_mant(out_val)) && (_desc(out_val).clss == SUBNORMAL))
+ _desc(out_val).clss = ZERO;
/* check for rounding overflow */
hsb = 2 + _desc(out_val).mantissa_size - sc_get_highest_set_bit(_mant(out_val)) - 1;
/* check for rounding overflow */
hsb = 2 + _desc(out_val).mantissa_size - sc_get_highest_set_bit(_mant(out_val)) - 1;
- if ((_desc(out_val).class != SUBNORMAL) && (hsb < -1))
+ if ((_desc(out_val).clss != SUBNORMAL) && (hsb < -1))
{
sc_val_from_ulong(1, temp);
_shift_right(_mant(out_val), temp, _mant(out_val));
sc_add(_exp(out_val), temp, _exp(out_val));
}
{
sc_val_from_ulong(1, temp);
_shift_right(_mant(out_val), temp, _mant(out_val));
sc_add(_exp(out_val), temp, _exp(out_val));
}
- else if ((_desc(out_val).class == SUBNORMAL) && (hsb == -1))
+ else if ((_desc(out_val).clss == SUBNORMAL) && (hsb == -1))
{
/* 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));
- _desc(out_val).class = NORMAL;
+ _desc(out_val).clss = NORMAL;
}
/* 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
switch (rounding_mode) {
case FC_TONEAREST:
case FC_TOPOSITIVE:
switch (rounding_mode) {
case FC_TONEAREST:
case FC_TOPOSITIVE:
- _desc(out_val).class = INF;
+ _desc(out_val).clss = INF;
break;
case FC_TONEGATIVE:
break;
case FC_TONEGATIVE:
switch (rounding_mode) {
case FC_TONEAREST:
case FC_TONEGATIVE:
switch (rounding_mode) {
case FC_TONEAREST:
case FC_TONEGATIVE:
- _desc(out_val).class = INF;
+ _desc(out_val).clss = INF;
break;
case FC_TOPOSITIVE:
break;
case FC_TOPOSITIVE:
+/**
+ * Operations involving NaN's must return NaN
+ */
+#define handle_NAN(a, b, result) \
+do { \
+ if (_desc(a).clss == NAN) { \
+ if (a != result) memcpy(result, a, calc_buffer_size); \
+ return result; \
+ } \
+ if (_desc(b).clss == NAN) { \
+ if (b != result) memcpy(result, b, calc_buffer_size); \
+ return result; \
+ } \
+}while (0)
+
+
+/**
* calculate a + b, where a is the value with the bigger exponent
*/
* calculate a + b, where a is the value with the bigger exponent
*/
-static char* _add(const char* a, const char* b, char* result)
+static char* _fadd(const char* a, const char* b, char* result)
{
char *temp;
char *exp_diff;
{
char *temp;
char *exp_diff;
- if (_desc(a).class == NAN) {
- if (a != result) memcpy(result, a, calc_buffer_size);
- return result;
- }
- if (_desc(b).class == NAN) {
- if (b != result) memcpy(result, b, calc_buffer_size);
- return result;
- }
+ handle_NAN(a, b, result);
/* make sure result has a descriptor */
if (result != a && result != b)
/* make sure result has a descriptor */
if (result != a && result != b)
sign = _sign(a) ^ _sign(b);
/* produce NaN on inf - inf */
sign = _sign(a) ^ _sign(b);
/* produce NaN on inf - inf */
- if (sign && (_desc(a).class == INF) && (_desc(b).class == INF))
+ if (sign && (_desc(a).clss == INF) && (_desc(b).clss == INF))
return fc_get_qnan(_desc(a).exponent_size, _desc(b).mantissa_size, result);
return fc_get_qnan(_desc(a).exponent_size, _desc(b).mantissa_size, result);
- temp = alloca(value_size);
+ temp = alloca(value_size);
exp_diff = alloca(value_size);
/* get exponent difference */
exp_diff = alloca(value_size);
/* get exponent difference */
if (sign && sc_val_to_long(exp_diff) == 0) {
switch (sc_comp(_mant(a), _mant(b))) {
case 1: /* a > b */
if (sign && sc_val_to_long(exp_diff) == 0) {
switch (sc_comp(_mant(a), _mant(b))) {
case 1: /* a > b */
- if (_sign(a)) _sign(result) = 1; /* abs(a) is bigger and a is negative */
- else _sign(result) = 0;
+ _sign(result) = _sign(a); /* abs(a) is bigger and a is negative */
break;
case 0: /* a == b */
break;
case 0: /* a == b */
- if (rounding_mode == FC_TONEGATIVE)
- _sign(result) = 1;
- else
- _sign(result) = 0;
+ _sign(result) = (rounding_mode == FC_TONEGATIVE);
break;
case -1: /* a < b */
break;
case -1: /* a < b */
- if (_sign(b)) _sign(result) = 1; /* abs(b) is bigger and b is negative */
- else _sign(result) = 0;
+ _sign(result) = _sign(b); /* abs(b) is bigger and b is negative */
break;
default:
/* can't be reached */
break;
}
break;
default:
/* can't be reached */
break;
}
- } else {
- _sign(result) = _sign(a);
+ else
+ _sign(result) = _sign(a);
/* sign has been taken care of, check for special cases */
/* sign has been taken care of, check for special cases */
- if (_desc(a).class == ZERO) {
+ if (_desc(a).clss == ZERO) {
if (b != result) memcpy(result+SIGN_POS+1, b+SIGN_POS+1, calc_buffer_size-SIGN_POS-1);
return result;
}
if (b != result) memcpy(result+SIGN_POS+1, b+SIGN_POS+1, calc_buffer_size-SIGN_POS-1);
return result;
}
- if (_desc(b).class == ZERO) {
+ if (_desc(b).clss == ZERO) {
if (a != result) memcpy(result+SIGN_POS+1, a+SIGN_POS+1, calc_buffer_size-SIGN_POS-1);
return result;
}
if (a != result) memcpy(result+SIGN_POS+1, a+SIGN_POS+1, calc_buffer_size-SIGN_POS-1);
return result;
}
- if (_desc(a).class == INF) {
+ if (_desc(a).clss == INF) {
if (a != result) memcpy(result+SIGN_POS+1, a+SIGN_POS+1, calc_buffer_size-SIGN_POS-1);
return result;
}
if (a != result) memcpy(result+SIGN_POS+1, a+SIGN_POS+1, calc_buffer_size-SIGN_POS-1);
return result;
}
- if (_desc(b).class == INF) {
+ if (_desc(b).clss == INF) {
if (b != result) memcpy(result+SIGN_POS+1, b+SIGN_POS+1, calc_buffer_size-SIGN_POS-1);
return result;
}
if (b != result) memcpy(result+SIGN_POS+1, b+SIGN_POS+1, calc_buffer_size-SIGN_POS-1);
return result;
}
/* 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 */
- if ((_desc(b).class == SUBNORMAL) && (_desc(a).class != SUBNORMAL))
+ if ((_desc(b).clss == SUBNORMAL) && (_desc(a).clss != SUBNORMAL))
{
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 */
- if ((_desc(a).class == SUBNORMAL) && (_desc(b).class == SUBNORMAL))
+ if ((_desc(a).clss == SUBNORMAL) && (_desc(b).clss == SUBNORMAL))
{
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));
return _normalize(result, result, sticky);
}
return _normalize(result, result, sticky);
}
-static char* _mul(const char* a, const char* b, char* result)
+/**
+ * calculate a * b
+ */
+static char* _fmul(const char* a, const char* b, char* result)
- if (_desc(a).class == NAN) {
- if (a != result) memcpy(result, a, calc_buffer_size);
- return result;
- }
- if (_desc(b).class == NAN) {
- if (b != result) memcpy(result, b, calc_buffer_size);
- return result;
- }
+ handle_NAN(a, b, result);
temp = alloca(value_size);
temp = alloca(value_size);
_sign(result) = _sign(a) ^ _sign(b);
/* produce NaN on 0 * inf */
_sign(result) = _sign(a) ^ _sign(b);
/* produce NaN on 0 * inf */
- if (_desc(a).class == ZERO) {
- if (_desc(b).class == INF)
+ if (_desc(a).clss == ZERO) {
+ if (_desc(b).clss == INF)
fc_get_qnan(_desc(a).exponent_size, _desc(a).mantissa_size, result);
else
if (a != result) memcpy(result+SIGN_POS+1, a+SIGN_POS+1, calc_buffer_size-1);
return result;
}
fc_get_qnan(_desc(a).exponent_size, _desc(a).mantissa_size, result);
else
if (a != result) memcpy(result+SIGN_POS+1, a+SIGN_POS+1, calc_buffer_size-1);
return result;
}
- if (_desc(b).class == ZERO) {
- if (_desc(a).class == INF)
+ if (_desc(b).clss == ZERO) {
+ if (_desc(a).clss == INF)
fc_get_qnan(_desc(a).exponent_size, _desc(a).mantissa_size, result);
else
if (b != result) memcpy(result+SIGN_POS+1, b+SIGN_POS+1, calc_buffer_size-1);
return result;
}
fc_get_qnan(_desc(a).exponent_size, _desc(a).mantissa_size, result);
else
if (b != result) memcpy(result+SIGN_POS+1, b+SIGN_POS+1, calc_buffer_size-1);
return result;
}
- if (_desc(a).class == INF) {
+ if (_desc(a).clss == INF) {
if (a != result) memcpy(result+SIGN_POS+1, a+SIGN_POS+1, calc_buffer_size-1);
return result;
}
if (a != result) memcpy(result+SIGN_POS+1, a+SIGN_POS+1, calc_buffer_size-1);
return result;
}
- if (_desc(b).class == INF) {
+ if (_desc(b).clss == INF) {
if (b != result) memcpy(result+SIGN_POS+1, b+SIGN_POS+1, calc_buffer_size-1);
return result;
}
if (b != result) memcpy(result+SIGN_POS+1, b+SIGN_POS+1, calc_buffer_size-1);
return 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 */
- if ((_desc(a).class == SUBNORMAL) ^ (_desc(b).class == SUBNORMAL))
+ if ((_desc(a).clss == SUBNORMAL) ^ (_desc(b).clss == SUBNORMAL))
{
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));
return _normalize(result, result, sc_had_carry());
}
return _normalize(result, result, sc_had_carry());
}
-static char* _div(const char* a, const char* b, char* result)
+/**
+ * calculate a / b
+ */
+static char* _fdiv(const char* a, const char* b, char* result)
- if (_desc(a).class == NAN) {
- if (a != result) memcpy(result, a, calc_buffer_size);
- return result;
- }
- if (_desc(b).class == NAN) {
- if (b != result) memcpy(result, b, calc_buffer_size);
- return result;
- }
+ handle_NAN(a, b, result);
temp = alloca(value_size);
dividend = alloca(value_size);
temp = alloca(value_size);
dividend = alloca(value_size);
_sign(result) = _sign(a) ^ _sign(b);
/* produce nan on 0/0 and inf/inf */
_sign(result) = _sign(a) ^ _sign(b);
/* produce nan on 0/0 and inf/inf */
- if (_desc(a).class == ZERO) {
- if (_desc(b).class == ZERO)
+ if (_desc(a).clss == ZERO) {
+ if (_desc(b).clss == ZERO)
/* 0/0 -> nan */
fc_get_qnan(_desc(a).exponent_size, _desc(a).mantissa_size, result);
else
/* 0/0 -> nan */
fc_get_qnan(_desc(a).exponent_size, _desc(a).mantissa_size, result);
else
- if (_desc(b).class == INF) {
- if (_desc(a).class == INF)
+ if (_desc(b).clss == INF) {
+ if (_desc(a).clss == INF)
/* inf/inf -> nan */
fc_get_qnan(_desc(a).exponent_size, _desc(a).mantissa_size, result);
else {
/* inf/inf -> nan */
fc_get_qnan(_desc(a).exponent_size, _desc(a).mantissa_size, result);
else {
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));
- _desc(result).class = ZERO;
+ _desc(result).clss = ZERO;
- if (_desc(a).class == INF) {
+ if (_desc(a).clss == INF) {
/* inf/x -> inf */
if (a != result) memcpy(result+SIGN_POS+1, a+SIGN_POS+1, calc_buffer_size-1);
return result;
}
/* inf/x -> inf */
if (a != result) memcpy(result+SIGN_POS+1, a+SIGN_POS+1, calc_buffer_size-1);
return result;
}
- if (_desc(b).class == ZERO) {
+ if (_desc(b).clss == ZERO) {
/* division by zero */
if (_sign(result))
fc_get_minusinf(_desc(a).exponent_size, _desc(a).mantissa_size, result);
/* division by zero */
if (_sign(result))
fc_get_minusinf(_desc(a).exponent_size, _desc(a).mantissa_size, 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 */
- if ((_desc(a).class == SUBNORMAL) ^ (_desc(b).class == SUBNORMAL))
+ if ((_desc(a).clss == SUBNORMAL) ^ (_desc(b).clss == SUBNORMAL))
{
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));
return _normalize(result, result, sc_had_carry());
}
return _normalize(result, result, sc_had_carry());
}
-void _power_of_ten(int exp, descriptor_t *desc, char *result)
+static void _power_of_ten(int exp, descriptor_t *desc, char *result)
{
char *build;
char *temp;
{
char *build;
char *temp;
+/**
+ * Truncate the fractional part away.
+ *
+ * This does not clip to any integer rang.
+ */
static char* _trunc(const char *a, char *result)
{
static char* _trunc(const char *a, char *result)
{
- /* when exponent == 0 all bits left of the radix point
+ /*
+ * When exponent == 0 all bits left of the radix point
* are the integral part of the value. For 15bit exp_size
* this would require a left shift of max. 16383 bits which
* is too much.
* are the integral part of the value. For 15bit exp_size
* this would require a left shift of max. 16383 bits which
* is too much.
* point remains set. This restricts the interesting
* exponents to the interval [0, mant_size-1].
* Outside this interval the truncated value is either 0 or
* point remains set. This restricts the interesting
* exponents to the interval [0, mant_size-1].
* Outside this interval the truncated value is either 0 or
- * it is are already truncated */
+ * it does not have fractional parts.
+ */
int exp_bias, exp_val;
char *temp;
int exp_bias, exp_val;
char *temp;
memcpy(&_desc(result), &_desc(a), sizeof(descriptor_t));
exp_bias = (1<<_desc(a).exponent_size)/2-1;
memcpy(&_desc(result), &_desc(a), sizeof(descriptor_t));
exp_bias = (1<<_desc(a).exponent_size)/2-1;
- exp_val = sc_val_to_long(_exp(a)) - exp_bias;
+ exp_val = sc_val_to_long(_exp(a)) - exp_bias;
if (exp_val < 0) {
sc_val_from_ulong(0, NULL);
_save_result(_exp(result));
_save_result(_mant(result));
if (exp_val < 0) {
sc_val_from_ulong(0, NULL);
_save_result(_exp(result));
_save_result(_mant(result));
- _desc(result).class = ZERO;
+ _desc(result).clss = ZERO;
/* make the value with the bigger exponent the first one */
TRACEPRINTF(("+ %s ", fc_print(b, buffer, 100, FC_PACKED)));
if (sc_comp(_exp(a), _exp(b)) == -1)
/* make the value with the bigger exponent the first one */
TRACEPRINTF(("+ %s ", fc_print(b, buffer, 100, FC_PACKED)));
if (sc_comp(_exp(a), _exp(b)) == -1)
break;
case FC_sub:
TRACEPRINTF(("- %s ", fc_print(b, buffer, 100, FC_PACKED)));
break;
case FC_sub:
TRACEPRINTF(("- %s ", fc_print(b, buffer, 100, FC_PACKED)));
memcpy(temp, b, calc_buffer_size);
_sign(temp) = !_sign(b);
if (sc_comp(_exp(a), _exp(temp)) == -1)
memcpy(temp, b, calc_buffer_size);
_sign(temp) = !_sign(b);
if (sc_comp(_exp(a), _exp(temp)) == -1)
+ _fadd(temp, a, result);
+ _fadd(a, temp, result);
break;
case FC_mul:
TRACEPRINTF(("* %s ", fc_print(b, buffer, 100, FC_PACKED)));
break;
case FC_mul:
TRACEPRINTF(("* %s ", fc_print(b, buffer, 100, FC_PACKED)));
break;
case FC_div:
TRACEPRINTF(("/ %s ", fc_print(b, buffer, 100, FC_PACKED)));
break;
case FC_div:
TRACEPRINTF(("/ %s ", fc_print(b, buffer, 100, FC_PACKED)));
break;
case FC_neg:
TRACEPRINTF(("negated "));
break;
case FC_neg:
TRACEPRINTF(("negated "));
_sign(result) = !_sign(a);
break;
case FC_int:
_sign(result) = !_sign(a);
break;
case FC_int:
+ TRACEPRINTF(("truncated to integer "));
_trunc(a, result);
break;
case FC_rnd:
_trunc(a, result);
break;
case FC_rnd:
+ TRACEPRINTF(("rounded to integer "));
+ assert(0);
_desc(result).exponent_size = exp_size;
_desc(result).mantissa_size = mant_size;
_desc(result).exponent_size = exp_size;
_desc(result).mantissa_size = mant_size;
- _desc(result).class = NORMAL;
+ _desc(result).clss = NORMAL;
_power_of_ten(exp_int, &_desc(result), power_val);
_power_of_ten(exp_int, &_desc(result), power_val);
- _div(result, power_val, result);
+ _fdiv(result, power_val, result);
/* sign and flag suffice to identify nan or inf, no exponent/mantissa
* encoding is needed. the function can return immediately in these cases */
if (isnan(l)) {
/* sign and flag suffice to identify nan or inf, no exponent/mantissa
* encoding is needed. the function can return immediately in these cases */
if (isnan(l)) {
- _desc(result).class = NAN;
+ _desc(result).clss = NAN;
TRACEPRINTF(("val_from_float resulted in NAN\n"));
return result;
}
else if (isinf(l)) {
TRACEPRINTF(("val_from_float resulted in NAN\n"));
return result;
}
else if (isinf(l)) {
- _desc(result).class = INF;
+ _desc(result).clss = INF;
TRACEPRINTF(("val_from_float resulted in %sINF\n", (_sign(result)==1)?"-":""));
return result;
}
TRACEPRINTF(("val_from_float resulted in %sINF\n", (_sign(result)==1)?"-":""));
return result;
}
/* set the descriptor of the new value */
_desc(result).exponent_size = exp_size;
_desc(result).mantissa_size = mant_size;
/* set the descriptor of the new value */
_desc(result).exponent_size = exp_size;
_desc(result).mantissa_size = mant_size;
- _desc(result).class = _desc(value).class;
+ _desc(result).clss = _desc(value).clss;
_sign(result) = _sign(value);
_sign(result) = _sign(value);
sc_add(_exp(value), temp, _exp(result));
/* _normalize expects normalized radix point */
sc_add(_exp(value), temp, _exp(result));
/* _normalize expects normalized radix point */
- if (_desc(val).class == SUBNORMAL) {
+ if (_desc(val).clss == SUBNORMAL) {
sc_val_from_ulong(1, NULL);
_shift_left(_mant(val), sc_get_buffer(), _mant(result));
} else if (value != result) {
sc_val_from_ulong(1, NULL);
_shift_left(_mant(val), sc_get_buffer(), _mant(result));
} else if (value != result) {
_desc(result).exponent_size = exponent_size;
_desc(result).mantissa_size = mantissa_size;
_desc(result).exponent_size = exponent_size;
_desc(result).mantissa_size = mantissa_size;
- _desc(result).class = NORMAL;
+ _desc(result).clss = NORMAL;
_desc(result).exponent_size = exponent_size;
_desc(result).mantissa_size = mantissa_size;
_desc(result).exponent_size = exponent_size;
_desc(result).mantissa_size = mantissa_size;
- _desc(result).class = NAN;
+ _desc(result).clss = NAN;
_desc(result).exponent_size = exponent_size;
_desc(result).mantissa_size = mantissa_size;
_desc(result).exponent_size = exponent_size;
_desc(result).mantissa_size = mantissa_size;
- _desc(result).class = NAN;
+ _desc(result).clss = NAN;
_desc(result).exponent_size = exponent_size;
_desc(result).mantissa_size = mantissa_size;
_desc(result).exponent_size = exponent_size;
_desc(result).mantissa_size = mantissa_size;
- _desc(result).class = NORMAL;
+ _desc(result).clss = NORMAL;
* Unordered if NaN or equal
*/
if (a == b)
* Unordered if NaN or equal
*/
if (a == b)
- return _desc(val_a).class == NAN ? 2 : 0;
+ return _desc(val_a).clss == NAN ? 2 : 0;
/* unordered if one is a NaN */
/* unordered if one is a NaN */
- if (_desc(val_a).class == NAN || _desc(val_b).class == NAN)
+ if (_desc(val_a).clss == NAN || _desc(val_b).clss == NAN)
return 2;
/* zero is equal independent of sign */
return 2;
/* zero is equal independent of sign */
- if ((_desc(val_a).class == ZERO) && (_desc(val_b).class == ZERO))
+ if ((_desc(val_a).clss == ZERO) && (_desc(val_b).clss == ZERO))
return 0;
/* different signs make compare easy */
return 0;
/* different signs make compare easy */
mul = _sign(a) ? -1 : 1;
/* both infinity means equality */
mul = _sign(a) ? -1 : 1;
/* both infinity means equality */
- if ((_desc(val_a).class == INF) && (_desc(val_b).class == INF))
+ if ((_desc(val_a).clss == INF) && (_desc(val_b).clss == INF))
return 0;
/* infinity is bigger than the rest */
return 0;
/* infinity is bigger than the rest */
- if (_desc(val_a).class == INF)
+ if (_desc(val_a).clss == INF)
- if (_desc(val_b).class == INF)
+ if (_desc(val_b).clss == INF)
return -1 * mul;
/* check first exponent, that mantissa if equal */
return -1 * mul;
/* check first exponent, that mantissa if equal */
int fc_is_zero(const void *a)
{
int fc_is_zero(const void *a)
{
- return _desc(a).class == ZERO;
+ return _desc(a).clss == ZERO;
}
int fc_is_negative(const void *a)
}
int fc_is_negative(const void *a)
int fc_is_inf(const void *a)
{
int fc_is_inf(const void *a)
{
- return _desc(a).class == INF;
+ return _desc(a).clss == INF;
}
int fc_is_nan(const void *a)
{
}
int fc_is_nan(const void *a)
{
- return _desc(a).class == NAN;
+ return _desc(a).clss == NAN;
}
int fc_is_subnormal(const void *a)
{
}
int fc_is_subnormal(const void *a)
{
- return _desc(a).class == SUBNORMAL;
+ return _desc(a).clss == SUBNORMAL;
}
char *fc_print(const void *a, char *buf, int buflen, unsigned base)
}
char *fc_print(const void *a, char *buf, int buflen, unsigned base)
switch (base) {
case FC_DEC:
switch (base) {
case FC_DEC:
- switch (_desc(val).class) {
+ switch (_desc(val).clss) {
case INF:
if (buflen >= 8+_sign(val)) sprintf(buf, "%sINFINITY", _sign(val)?"-":"");
else snprintf(buf, buflen, "%sINF", _sign(val)?"-":NULL);
case INF:
if (buflen >= 8+_sign(val)) sprintf(buf, "%sINFINITY", _sign(val)?"-":"");
else snprintf(buf, buflen, "%sINF", _sign(val)?"-":NULL);
- switch (_desc(val).class) {
+ switch (_desc(val).clss) {
case INF:
if (buflen >= 8+_sign(val)) sprintf(buf, "%sINFINITY", _sign(val)?"-":"");
else snprintf(buf, buflen, "%sINF", _sign(val)?"-":NULL);
case INF:
if (buflen >= 8+_sign(val)) sprintf(buf, "%sINFINITY", _sign(val)?"-":"");
else snprintf(buf, buflen, "%sINF", _sign(val)?"-":NULL);
if (max_precision < precision)
printf("WARING: not enough precision available, using %d\n", max_precision);
if (max_precision < precision)
printf("WARING: not enough precision available, using %d\n", max_precision);
- rounding_mode = FC_TONEAREST;
- value_size = sc_get_buffer_length();
- SIGN_POS = 0;
- EXPONENT_POS = SIGN_POS + sizeof(char);
- MANTISSA_POS = EXPONENT_POS + value_size;
- DESCRIPTOR_POS = MANTISSA_POS + value_size;
+ rounding_mode = FC_TONEAREST;
+ value_size = sc_get_buffer_length();
+ SIGN_POS = 0;
+ EXPONENT_POS = SIGN_POS + sizeof(char);
+ MANTISSA_POS = EXPONENT_POS + value_size;
+ DESCRIPTOR_POS = MANTISSA_POS + value_size;
calc_buffer_size = DESCRIPTOR_POS + sizeof(descriptor_t);
calc_buffer = xmalloc(calc_buffer_size);
calc_buffer_size = DESCRIPTOR_POS + sizeof(descriptor_t);
calc_buffer = xmalloc(calc_buffer_size);