mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-19 02:00:26 +02:00
(scm_i_print_complex, icmplx2str): New.
(iflo2str): Use icmplx2str for complex numbers.
This commit is contained in:
parent
cbdc837976
commit
7a1aba42cf
2 changed files with 30 additions and 14 deletions
|
@ -2195,6 +2195,25 @@ idbl2str (double f, char *a, int radix)
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static size_t
|
||||||
|
icmplx2str (double real, double imag, char *str, int radix)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = idbl2str (real, str, radix);
|
||||||
|
if (imag != 0.0)
|
||||||
|
{
|
||||||
|
/* Don't output a '+' for negative numbers or for Inf and
|
||||||
|
NaN. They will provide their own sign. */
|
||||||
|
if (0 <= imag && !xisinf (imag) && !xisnan (imag))
|
||||||
|
str[i++] = '+';
|
||||||
|
i += idbl2str (imag, &str[i], radix);
|
||||||
|
str[i++] = 'i';
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
static size_t
|
static size_t
|
||||||
iflo2str (SCM flt, char *str, int radix)
|
iflo2str (SCM flt, char *str, int radix)
|
||||||
{
|
{
|
||||||
|
@ -2202,19 +2221,8 @@ iflo2str (SCM flt, char *str, int radix)
|
||||||
if (SCM_REALP (flt))
|
if (SCM_REALP (flt))
|
||||||
i = idbl2str (SCM_REAL_VALUE (flt), str, radix);
|
i = idbl2str (SCM_REAL_VALUE (flt), str, radix);
|
||||||
else
|
else
|
||||||
{
|
i = icmplx2str (SCM_COMPLEX_REAL (flt), SCM_COMPLEX_IMAG (flt),
|
||||||
i = idbl2str (SCM_COMPLEX_REAL (flt), str, radix);
|
str, radix);
|
||||||
if (SCM_COMPLEX_IMAG (flt) != 0.0)
|
|
||||||
{
|
|
||||||
double imag = SCM_COMPLEX_IMAG (flt);
|
|
||||||
/* Don't output a '+' for negative numbers or for Inf and
|
|
||||||
NaN. They will provide their own sign. */
|
|
||||||
if (0 <= imag && !xisinf (imag) && !xisnan (imag))
|
|
||||||
str[i++] = '+';
|
|
||||||
i += idbl2str (imag, &str[i], radix);
|
|
||||||
str[i++] = 'i';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2331,6 +2339,13 @@ scm_print_complex (SCM sexp, SCM port, scm_print_state *pstate SCM_UNUSED)
|
||||||
return !0;
|
return !0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
scm_i_print_complex (double real, double imag, SCM port)
|
||||||
|
{
|
||||||
|
char num_buf[FLOBUFLEN];
|
||||||
|
scm_lfwrite (num_buf, icmplx2str (real, imag, num_buf, 10), port);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
scm_i_print_fraction (SCM sexp, SCM port, scm_print_state *pstate SCM_UNUSED)
|
scm_i_print_fraction (SCM sexp, SCM port, scm_print_state *pstate SCM_UNUSED)
|
||||||
{
|
{
|
||||||
|
@ -5746,7 +5761,7 @@ scm_to_double (SCM val)
|
||||||
else if (SCM_REALP (val))
|
else if (SCM_REALP (val))
|
||||||
return SCM_REAL_VALUE (val);
|
return SCM_REAL_VALUE (val);
|
||||||
else
|
else
|
||||||
scm_wrong_type_arg (NULL, 0, val);
|
scm_wrong_type_arg_msg (NULL, 0, val, "real number");
|
||||||
}
|
}
|
||||||
|
|
||||||
SCM
|
SCM
|
||||||
|
|
|
@ -284,6 +284,7 @@ SCM_API int scm_i_print_fraction (SCM sexp, SCM port, scm_print_state *pstate);
|
||||||
|
|
||||||
/* general internal functions */
|
/* general internal functions */
|
||||||
SCM_API void scm_i_print_double (double val, SCM port);
|
SCM_API void scm_i_print_double (double val, SCM port);
|
||||||
|
SCM_API void scm_i_print_complex (double real, double imag, SCM port);
|
||||||
|
|
||||||
/* conversion functions for integers */
|
/* conversion functions for integers */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue