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
))
38 for (l
= SCM_NUMDIGS (num
); l
--;)
40 ITYPE
new = SCM_I_BIGUP (ITYPE
, res
) + SCM_BDIGITS (num
)[l
];
43 && !(new == MIN_VALUE
&& l
== 0)
46 scm_out_of_range (s_caller
, num
);
50 if (SCM_BIGSIGN (num
))
52 scm_out_of_range (s_caller
, num
);
59 scm_out_of_range (s_caller
, num
);
67 scm_out_of_range (s_caller
, num
);
73 scm_wrong_type_arg (s_caller
, pos
, num
);
77 INTEGRAL2NUM (ITYPE n
)
79 if (sizeof (ITYPE
) < sizeof (scm_t_signed_bits
)
87 return SCM_MAKINUM ((scm_t_signed_bits
) n
);
90 return INTEGRAL2BIG (n
);
92 return scm_make_real ((double) n
);
99 INTEGRAL2BIG (ITYPE n
)
103 unsigned int n_digits
;
118 (sizeof (ITYPE
) + sizeof (SCM_BIGDIG
) - 1) / sizeof (SCM_BIGDIG
);
123 for (tn
= n
, n_digits
= 0;
125 ++n_digits
, tn
= SCM_BIGDN (tn
))
130 res
= scm_i_mkbig (n_digits
, neg_p
);
131 digits
= SCM_BDIGITS (res
);
135 digits
[i
++] = SCM_BIGLO (n
);