#include "xmalloc.h"
-/** The number of extra precesion rounding bits */
+/** The number of extra precision rounding bits */
#define ROUNDING_BITS 2
typedef uint32_t UINT32;
value_t buildval;
ieee_descriptor_t desc;
+ unsigned mantissa_size;
#ifdef HAVE_LONG_DOUBLE
desc.exponent_size = 15;
desc.explicit_one = 0;
desc.clss = NORMAL;
#endif
+ mantissa_size = desc.mantissa_size + desc.explicit_one;
temp = alloca(calc_buffer_size);
value = fc_cast(val, &desc, temp);
mantissa1 = 0;
for (byte_offset = 0; byte_offset < 4; byte_offset++)
- mantissa1 |= sc_sub_bits(_mant(value), desc.mantissa_size, byte_offset) << (byte_offset<<3);
+ mantissa1 |= sc_sub_bits(_mant(value), mantissa_size, byte_offset) << (byte_offset << 3);
for (; (byte_offset<<3) < desc.mantissa_size; byte_offset++)
- mantissa0 |= sc_sub_bits(_mant(value), desc.mantissa_size, byte_offset) << ((byte_offset-4)<<3);
+ mantissa0 |= sc_sub_bits(_mant(value), mantissa_size, byte_offset) << ((byte_offset - 4) << 3);
#ifdef HAVE_LONG_DOUBLE
buildval.val.high = sign << 15;
char *fc_print(const fp_value *val, char *buf, int buflen, unsigned base) {
char *mul_1;
+ LLDBL flt_val;
mul_1 = alloca(calc_buffer_size);
snprintf(buf, buflen, "0.0");
break;
default:
- /* XXX to be implemented */
+ flt_val = fc_val_to_ieee754(val);
#ifdef HAVE_LONG_DOUBLE
/* XXX 30 is arbitrary */
- snprintf(buf, buflen, "%.30LE", fc_val_to_ieee754(val));
+ snprintf(buf, buflen, "%.30LE", flt_val);
#else
- snprintf(buf, buflen, "%.18E", fc_val_to_ieee754(val));
+ snprintf(buf, buflen, "%.18E", flt_val);
#endif
}
break;
snprintf(buf, buflen, "0.0");
break;
default:
+ flt_val = fc_val_to_ieee754(val);
#ifdef HAVE_LONG_DOUBLE
- snprintf(buf, buflen, "%LA", fc_val_to_ieee754(val));
+ snprintf(buf, buflen, "%LA", flt_val);
#else
- snprintf(buf, buflen, "%A", fc_val_to_ieee754(val));
+ snprintf(buf, buflen, "%A", flt_val);
#endif
}
break;
/* does nothing if already init */
if (precision == 0) precision = FC_DEFAULT_PRECISION;
- init_strcalc(precision + 4);
+ init_strcalc(precision + 2 + ROUNDING_BITS);
- /* needs additionally two bits to round, a bit as explicit 1., and one for
+ /* needs additionally rounding bits, one bit as explicit 1., and one for
* addition overflow */
- max_precision = sc_get_precision() - 4;
+ max_precision = sc_get_precision() - (2 + ROUNDING_BITS);
if (max_precision < precision)
printf("WARNING: not enough precision available, using %d\n", max_precision);