repo.or.cz
/
altfloat.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
types: Use operations in GHC.Prim for double <=> float conversions.
[altfloat.git]
/
cfloat.c
blob
dae95e170b06fe8feefaca0a909fac2dedd8197a
1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <errno.h>
4
#include <math.h>
5
6
#include
"cfloat.h"
7
8
int
double_to_string
(
char
*
buf
,
double
val
)
9
{
10
if
(
buf
==
NULL
)
11
return
snprintf
(
NULL
,
0
,
"%a"
,
val
);
12
return
sprintf
(
buf
,
"%a"
,
val
);
13
}
14
15
double
double_signum
(
double
val
)
16
{
17
if
(
signbit
(
val
))
18
return
-
1
;
19
return
1
;
20
}
21
22
int
double_classify
(
double
val
)
23
{
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
;
35
}
36
37
return
-
1
;
38
}