diff options
author | Mark H Weaver <mhw@netris.org> | 2011-02-02 05:29:55 -0500 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2011-02-02 21:34:01 +0100 |
commit | c721848287984e668a4f2fe7c3accba4a1bd8d10 (patch) | |
tree | 83a2318cfe5ee2308f944af929b22b24e2c9e774 /doc/ref/api-data.texi | |
parent | 9b9ef10cf06db2c0349fb6e0ce6a5c4fa48341d1 (diff) | |
download | guile-c721848287984e668a4f2fe7c3accba4a1bd8d10.tar.gz |
Support non-real complex numbers with inexact zero imaginary part
Add the ability to represent non-real complex numbers whose imaginary
part is an _inexact_ zero (0.0 or -0.0), per R6RS. Previously, such
numbers were immediately changed into inexact reals.
* libguile/numbers.c: Remove from the list of `General assumptions' in
numbers.c that objects satisfying SCM_COMPLEXP() have a non-zero
complex component. This is no longer true. Also add a warning
about another unrelated assumption that is not entirely correct
(that floor(r) == r implies that mpz_set_d will DTRT; it won't
if r is infinite).
(icmplx2str): Always print the imaginary part, even if it is zero.
Also handle a negative zero imaginary part more gracefully. It
now prints 0.0-0.0i, where previously it would print 0.0+-0.0i.
(mem2ureal): Replace scm_from_double (0.0) with flo0.
(scm_c_make_rectangular): Always create non-real complex numbers.
Previously it would create inexact reals if the specified imaginary
part was zero.
(scm_make_rectangular): If the imaginary part is an _exact_ 0, return
the real part unchanged (possibly exact), otherwise return a non-real
complex number (possibly with an inexact zero imaginary part).
Previously, it would return an inexact real number whenever the
imaginary part was any kind of zero.
(scm_make_polar): If the magnitude is an exact 0, return an exact 0.
If the angle is an exact 0, return the magnitude unchanged (possibly
exact). Otherwise return a non-real complex number (possibly with an
inexact zero imaginary part). Previously, it would return a real
number whenever the imaginary part was any kind of zero.
(scm_imag_part): Return an exact 0 if applied to a real number.
Previously it would return an inexact zero if applied to an inexact
real number.
(scm_inexact_to_exact): Accept complex numbers with inexact zero
imaginary part. In that case, simply use the real part and ignore the
imaginary part. Essentially we coerce the inexact zero imaginary part
to an exact 0.
* test-suite/tests/numbers.test: Add many test cases, and modify
existing tests as needed to reflect these changes. Also add a new
internal predicate: `almost-real-nan?' which tests for a non-real
complex number with zero imaginary part whose real part is a NaN.
* doc/ref/api-data.texi (Complex Numbers): Update description of complex
numbers to reflect these changes: non-real complex numbers in Guile
need not have non-zero imaginary part. Also, each part of a complex
number may be any inexact real, not just rationals as was previously
stated. Explicitly mention that each part may be an infinity, a NaN,
or a signed zero.
(Complex Number Operations): Change the formal parameter names of
`make-polar' from `x' and `y' to `mag' and `ang'.
* NEWS: Add news entries.
Diffstat (limited to 'doc/ref/api-data.texi')
-rwxr-xr-x | doc/ref/api-data.texi | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/doc/ref/api-data.texi b/doc/ref/api-data.texi index 1ce9e1eee..9b065a595 100755 --- a/doc/ref/api-data.texi +++ b/doc/ref/api-data.texi @@ -683,11 +683,15 @@ angle, -1@@1.57079 @result{} 0.0-1.0i (approx) @end lisp -Guile represents a complex number with a non-zero imaginary part as a -pair of inexact rationals, so the real and imaginary parts of a -complex number have the same properties of inexactness and limited -precision as single inexact rational numbers. Guile can not represent -exact complex numbers with non-zero imaginary parts. +Guile represents a complex number as a pair of inexact reals, so the +real and imaginary parts of a complex number have the same properties of +inexactness and limited precision as single inexact real numbers. + +Note that each part of a complex number may contain any inexact real +value, including the special values @samp{+nan.0}, @samp{+inf.0} and +@samp{-inf.0}, as well as either of the signed zeroes @samp{0.0} or +@samp{-0.0}. + @deffn {Scheme Procedure} complex? z @deffnx {C Function} scm_complex_p (z) @@ -1077,10 +1081,10 @@ locale-dependent parsing). Return a complex number constructed of the given @var{real-part} and @var{imaginary-part} parts. @end deffn -@deffn {Scheme Procedure} make-polar x y -@deffnx {C Function} scm_make_polar (x, y) +@deffn {Scheme Procedure} make-polar mag ang +@deffnx {C Function} scm_make_polar (mag, ang) @cindex polar form -Return the complex number @var{x} * e^(i * @var{y}). +Return the complex number @var{mag} * e^(i * @var{ang}). @end deffn @c begin (texi-doc-string "guile" "real-part") |