2 * Authors: Matthias Heil
15 static long double value;
17 #define CAST_IN(val) (*((long double *)((val))))
18 #define CAST_OUT(val) ((void *)&(val))
20 #define CLEAR_BUFFER() memset((char*)&value, 0, sizeof(long double))
26 * functions defined in fltcalc.h
28 const void *fc_get_buffer(void)
30 return CAST_OUT(value);
33 const int fc_get_buffer_length(void)
35 return sizeof(long double);
38 void fc_val_from_str(const char *str, unsigned int len)
41 value = strtold(str, NULL);
44 void fc_val_from_float(long double l)
50 long double fc_val_to_float(const void *val)
55 void fc_get_min(unsigned int num_bits)
73 void fc_get_max(unsigned int num_bits)
93 /* nan: all exponent bit set, non-zero mantissa. not signalling wheni
94 * msb of mantissa is set (easily found using this struct */
95 union ieee854_long_double ld;
98 ld.ieee_nan.negative = 0;
99 ld.ieee_nan.exponent = 0x7FFF;
100 ld.ieee_nan.quiet_nan = 1;
101 ld.ieee_nan.mantissa0 = 42;
106 void fc_get_inf(void)
108 /* +-inf: all exponent bit set, sign is easy, one is strange XXX */
109 union ieee854_long_double ld;
112 ld.ieee_nan.negative = 0;
113 ld.ieee_nan.exponent = 0x7FFF;
114 ld.ieee_nan.quiet_nan = 0;
116 ld.ieee_nan.mantissa0 = 0;
117 ld.ieee_nan.mantissa1 = 0;
122 void fc_calc(const void *a, const void *b, int opcode)
128 value = CAST_IN(a) + CAST_IN(b);
131 value = CAST_IN(a) - CAST_IN(b);
134 value = CAST_IN(a) * CAST_IN(b);
137 value = CAST_IN(a) / CAST_IN(b);
144 int fc_comp(const void *a, const void *b)
146 if (CAST_IN(a) == CAST_IN(b)) return 0;
147 else return (CAST_IN(a) > CAST_IN(b))?(1):(-1);
150 char *fc_print_dec(const void *a)
152 static char buf[100];
154 snprintf(buf, 100, "%1.30Lg", CAST_IN(a));