1 /* this file is #include'd (many times) by numbers.c */
4 NUM2INTEGRAL (SCM num
, unsigned long int pos
, const char *s_caller
)
9 scm_t_signed_bits n
= SCM_INUM (num
);
13 scm_out_of_range (s_caller
, num
);
16 if (sizeof (ITYPE
) >= sizeof (scm_t_signed_bits
))
17 /* can't fit anything too big for this type in an inum
21 { /* an inum can be out of range, so check */
22 if (n
> (scm_t_signed_bits
)MAX_VALUE
24 || n
< (scm_t_signed_bits
)MIN_VALUE
27 scm_out_of_range (s_caller
, num
);
32 else if (SCM_BIGP (num
))
39 if (SCM_BIGSIGN (num
))
40 scm_out_of_range (s_caller
, num
);
43 for (l
= SCM_NUMDIGS (num
); l
--;)
45 ITYPE
new = SCM_I_BIGUP (ITYPE
, res
) + SCM_BDIGITS (num
)[l
];
48 && !(new == MIN_VALUE
&& l
== 0)
51 scm_out_of_range (s_caller
, num
);
58 if (SCM_BIGSIGN (num
))
64 scm_out_of_range (s_caller
, num
);
71 scm_out_of_range (s_caller
, num
);
76 scm_wrong_type_arg (s_caller
, pos
, num
);
80 INTEGRAL2NUM (ITYPE n
)
82 /* Determine at compile time whether we need to porferm the FIXABLE
83 test or not. This is not done to get more optimal code out of
84 the compiler (it can figure this out on its already), but to
85 avoid a spurious warning.
92 #ifdef NO_PREPRO_MAGIC
96 /*#if MAX_VALUE > SCM_MOST_POSITIVE_FIXNUM*/
100 /*#if MIN_VALUE<SCM_MOST_NEGATIVE_FIXNUM || MAX_VALUE>SCM_MOST_POSITIVE_FIXNUM*/
112 if (SCM_POSFIXABLE (n
))
115 return SCM_MAKINUM ((scm_t_signed_bits
) n
);
120 return INTEGRAL2BIG (n
);
122 return scm_make_real ((double) n
);
129 INTEGRAL2BIG (ITYPE n
)
133 unsigned int n_digits
;
148 (sizeof (ITYPE
) + sizeof (SCM_BIGDIG
) - 1) / sizeof (SCM_BIGDIG
);
153 for (tn
= n
, n_digits
= 0;
155 ++n_digits
, tn
= SCM_BIGDN (tn
))
160 res
= scm_i_mkbig (n_digits
, neg_p
);
161 digits
= SCM_BDIGITS (res
);
165 digits
[i
++] = SCM_BIGLO (n
);
182 #undef NO_PREPRO_MAGIC