mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 19:50:24 +02:00
(SCM_T_INTBUFLEN): Increased to cover
scm_t_intmax values. (scm_uint2str): New, for scm_t_uintmax. (scm_iint2str): Argument type changed to scm_t_intmax, reimplemented in terms of scm_uint2str.
This commit is contained in:
parent
77c2594f2f
commit
2881e77b5a
2 changed files with 27 additions and 15 deletions
|
@ -2218,29 +2218,38 @@ iflo2str (SCM flt, char *str, int radix)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* convert a long to a string (unterminated). returns the number of
|
/* convert a scm_t_intmax to a string (unterminated). returns the number of
|
||||||
characters in the result.
|
characters in the result.
|
||||||
rad is output base
|
rad is output base
|
||||||
p is destination: worst case (base 2) is SCM_INTBUFLEN */
|
p is destination: worst case (base 2) is SCM_INTBUFLEN */
|
||||||
size_t
|
size_t
|
||||||
scm_iint2str (long num, int rad, char *p)
|
scm_iint2str (scm_t_intmax num, int rad, char *p)
|
||||||
|
{
|
||||||
|
if (num < 0)
|
||||||
|
{
|
||||||
|
*p++ = '-';
|
||||||
|
return scm_iuint2str (-num, rad, p) + 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return scm_iuint2str (num, rad, p);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* convert a scm_t_intmax to a string (unterminated). returns the number of
|
||||||
|
characters in the result.
|
||||||
|
rad is output base
|
||||||
|
p is destination: worst case (base 2) is SCM_INTBUFLEN */
|
||||||
|
size_t
|
||||||
|
scm_iuint2str (scm_t_uintmax num, int rad, char *p)
|
||||||
{
|
{
|
||||||
size_t j = 1;
|
size_t j = 1;
|
||||||
size_t i;
|
size_t i;
|
||||||
unsigned long n = (num < 0) ? -num : num;
|
scm_t_uintmax n = num;
|
||||||
|
|
||||||
for (n /= rad; n > 0; n /= rad)
|
for (n /= rad; n > 0; n /= rad)
|
||||||
j++;
|
j++;
|
||||||
|
|
||||||
i = j;
|
i = j;
|
||||||
if (num < 0)
|
n = num;
|
||||||
{
|
|
||||||
*p++ = '-';
|
|
||||||
j++;
|
|
||||||
n = -num;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
n = num;
|
|
||||||
while (i--)
|
while (i--)
|
||||||
{
|
{
|
||||||
int d = n % rad;
|
int d = n % rad;
|
||||||
|
|
|
@ -111,10 +111,12 @@
|
||||||
#endif /* def FLT_MAX */
|
#endif /* def FLT_MAX */
|
||||||
|
|
||||||
|
|
||||||
/* SCM_INTBUFLEN is the maximum number of characters neccessary for the
|
/* SCM_INTBUFLEN is the maximum number of characters neccessary for
|
||||||
* printed or scm_string representation of an exact immediate.
|
* the printed or scm_string representation of an scm_t_intmax in
|
||||||
|
* radix 2. The buffer passed to scm_iint2str and scm_iuint2str must
|
||||||
|
* be of this size, for example.
|
||||||
*/
|
*/
|
||||||
#define SCM_INTBUFLEN (5 + SCM_LONG_BIT)
|
#define SCM_INTBUFLEN (5 + SCM_CHAR_BIT*sizeof(scm_t_intmax))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -208,7 +210,8 @@ SCM_API SCM scm_bit_extract (SCM n, SCM start, SCM end);
|
||||||
SCM_API SCM scm_logcount (SCM n);
|
SCM_API SCM scm_logcount (SCM n);
|
||||||
SCM_API SCM scm_integer_length (SCM n);
|
SCM_API SCM scm_integer_length (SCM n);
|
||||||
|
|
||||||
SCM_API size_t scm_iint2str (long num, int rad, char *p);
|
SCM_API size_t scm_iint2str (scm_t_intmax num, int rad, char *p);
|
||||||
|
SCM_API size_t scm_iuint2str (scm_t_uintmax num, int rad, char *p);
|
||||||
SCM_API SCM scm_number_to_string (SCM x, SCM radix);
|
SCM_API SCM scm_number_to_string (SCM x, SCM radix);
|
||||||
SCM_API int scm_print_real (SCM sexp, SCM port, scm_print_state *pstate);
|
SCM_API int scm_print_real (SCM sexp, SCM port, scm_print_state *pstate);
|
||||||
SCM_API int scm_print_complex (SCM sexp, SCM port, scm_print_state *pstate);
|
SCM_API int scm_print_complex (SCM sexp, SCM port, scm_print_state *pstate);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue