types: Use operations in GHC.Prim for double <=> float conversions.
[altfloat.git] / cfloat.c
blobdae95e170b06fe8feefaca0a909fac2dedd8197a
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <errno.h>
4 #include <math.h>
6 #include "cfloat.h"
8 int double_to_string(char *buf, double val)
10 if (buf == NULL)
11 return snprintf(NULL, 0, "%a", val);
12 return sprintf(buf, "%a", val);
15 double double_signum(double val)
17 if (signbit(val))
18 return -1;
19 return 1;
22 int double_classify(double val)
24 switch (fpclassify(val)) {
25 case FP_INFINITE:
26 return 0;
27 case FP_NAN:
28 return 1;
29 case FP_NORMAL:
30 return 2;
31 case FP_SUBNORMAL:
32 return 3;
33 case FP_ZERO:
34 return 4;
37 return -1;