+/* This code in included by number.s.c to generate integer conversion
+ functions like scm_to_int and scm_from_int. It is only for
+ unsigned types, see conv-integer.i.c for the signed variant.
+*/
+
+/* You need to define the following macros before including this
+ template. They are undefined at the end of this file to giove a
+ clean slate for the next inclusion.
+
+ TYPE - the integral type to be converted
+ TYPE_MIN - the smallest representable number of TYPE, typically 0.
+ TYPE_MAX - the largest representable number of TYPE
+ SIZEOF_TYPE - the size of TYPE, equal to "sizeof (TYPE)" but
+ in a form that can be computed by the preprocessor.
+ When this number is 0, the preprocessor is not used
+ to select which code to compile; the most general
+ code is always used.
+
+ SCM_TO_TYPE_PROTO(arg), SCM_FROM_TYPE_PROTO(arg)
+ - These two macros should expand into the prototype
+ for the two defined functions, without the return
+ type.
+
+*/
+
TYPE
SCM_TO_TYPE_PROTO (SCM val)
{
else
{
out_of_range:
- scm_out_of_range (NULL, val);
+ scm_i_range_error (val,
+ scm_from_unsigned_integer (TYPE_MIN),
+ scm_from_unsigned_integer (TYPE_MAX));
return 0;
}
}
#if SIZEOF_TYPE != 0 && SIZEOF_TYPE > SCM_SIZEOF_LONG
return n;
#else
- if (n >= TYPE_MIN && n <= TYPE_MAX)
- return n;
- else
- goto out_of_range;
+
+ if (n >= TYPE_MIN && n <= TYPE_MAX)
+ return n;
+ else
+ goto out_of_range;
+
#endif
}
else
if (n >= TYPE_MIN && n <= TYPE_MAX)
return n;
- else
- goto out_of_range;
+ else
+ goto out_of_range;
+
}
}
else
if (SCM_POSFIXABLE (val))
return SCM_I_MAKINUM (val);
else if (val <= ULONG_MAX)
- {
- SCM z = scm_double_cell (scm_tc16_big, 0, 0, 0);
- mpz_init_set_ui (SCM_I_BIG_MPZ (z), val);
- return z;
- }
+ return scm_i_ulong2big (val);
else
{
SCM z = scm_double_cell (scm_tc16_big, 0, 0, 0);