Commit | Line | Data |
---|---|---|
5437598b MD |
1 | /* this file is #include'd (several times) by numbers.c */ |
2 | ||
3 | FTYPE | |
4 | NUM2FLOAT (SCM num, unsigned long int pos, const char *s_caller) | |
5 | { | |
6 | if (SCM_INUMP (num)) | |
7 | return SCM_INUM (num); | |
8 | else if (SCM_BIGP (num)) | |
9 | { /* bignum */ | |
10 | ||
11 | FTYPE res = 0.0; | |
12 | size_t l; | |
13 | ||
14 | for (l = SCM_NUMDIGS (num); l--;) | |
15 | res = SCM_BIGRAD * res + SCM_BDIGITS (num)[l]; | |
16 | ||
17 | if (SCM_BIGSIGN (num)) | |
18 | res = -res; | |
19 | ||
20 | if (isfinite (res)) | |
21 | return res; | |
22 | else | |
23 | scm_out_of_range (s_caller, num); | |
24 | } | |
25 | else if (SCM_REALP (num)) | |
26 | return SCM_REAL_VALUE (num); | |
27 | else | |
28 | scm_wrong_type_arg (s_caller, pos, num); | |
29 | } | |
30 | ||
31 | SCM | |
32 | FLOAT2NUM (FTYPE n) | |
33 | { | |
34 | SCM z; | |
16d4699b | 35 | z = scm_alloc_double_cell (scm_tc16_real, 0, 0, 0); |
5437598b MD |
36 | SCM_REAL_VALUE (z) = n; |
37 | return z; | |
38 | } | |
39 | ||
40 | /* clean up */ | |
41 | #undef FLOAT2NUM | |
42 | #undef NUM2FLOAT | |
43 | #undef FTYPE | |
44 | ||
45 | /* | |
46 | Local Variables: | |
47 | c-file-style: "gnu" | |
48 | End: | |
49 | */ |