This site is a static rendering of the Trac instance that was used by R7RS-WG1 for its work on R7RS-small (PDF), which was ratified in 2013. For more information, see Home. For a version of this page that may be more recent, see CompnumsCowan in WG2's repo for R7RS-large.

# Compnums­Cowan

2016-08-06 23:15:24
source

The compnums are the subset of the inexact complex numbers whose real part and imaginary part are both flonums. This library is based on parts of FlonumsCowan lifted to compnums. A few procedures have been added from the C99 <complex.h> library.

## Specification

This section uses cx, cx1, cx2, etc., as parameter names for compnum arguments.

### Constructors

(compnum x)

The value returned is the compnum that is numerically closest to x. This procedure can be used to transform any complex number, exact or inexact, to a compnum.

(cxmake-rectangular fl1 fl2 )/div>

The value returned is the compnum whose real part is the flonum fl1 and whose imaginary part is the flonum fl2

(cxmake-polar fl1 fl 2 )

The value returned is the compnum that is numerically closest to the complex number whose magnitude is the flonum fl1 and whose angle is the flonum fl2

### Predicates

(compnum? obj)

Returns #t if obj is a compnum, #f otherwise.

(cx=? cx1 cx2 cx3 ...)

This procedure returns #t if its arguments are numerically equal.

(cxzero? cx)
(cxfinite? cx)
(cxinfinite? cx)
(cxnan? cx)

These numerical predicates test a compnum for a particular property, returning #t or #f. The cxzero? procedure tests whether it is cx=? to 0.0+0.0i, cxfinite? tests whether both the real and the imaginary parts are not an infinity and not a NaN, cxinfinite? tests whether either the real part or the imaginary part or both is an infinity, and cxnan? tests whether either the real part or the imaginary part or both is a NaN.

### Arithmetic operations

(cx+ cx1 ...)
(cx* cx1 ...)

These procedures return the compnum sum or product of their compnum arguments. In general, they should return the compnum that best approximates the mathematical sum or product. (For implementations that represent compnums using IEEE binary floating point, the meaning of “best” is defined by the IEEE standards.)

(cx/ cx1 cx2 ...)
(cx/ cx)

With two or more arguments, these procedures return the compnum difference or quotient of their compnum arguments, associating to the left. With one argument, however, they return the additive or multiplicative compnum inverse of their argument. In general, they should return the compnum that best approximates the mathematical difference or quotient. (For implementations that represent compnums using IEEE binary floating point, the meaning of “best” is reasonably well-defined by the IEEE standards.)

For undefined quotients, cx/ behaves as specified by the IEEE standards.

(cxreal-part cx)

This procedure returns the real part of cx as a flonum.

(cximag-part cx)

This procedure returns the imaginary part of cx as a flonum.

(cxangle cx)

This procedure returns the flonum that is the nearest approximation to the angle of cx.

(cxabs cx)
(cxmagnitude cx)

These procedures return the flonum that is the nearest approximation to the absolute value (magnitude) of cx.

(cxconj cx)

This procedure returns the complex conjugate of cx. The result has the same real part as the real part of cx; its imaginary part is the negation of the imaginary part of cx.

(cxproj cx)

This procedure returns the Riemann projection of cx. This is the same as cx unless cx has an infinite real part or imaginary part. In this case, the result is a compnum whose real part is 0.0 and whose imaginary part is either 0.0 or -0.0, depending on the sign of the imaginary part of cx.

(cxsignum cx)

This procedure returns a complex number whose phase is the same as z but whose magnitude is 1, unless z is zero, in which case it returns z.

### Transcendental functions

(cxexp cx)
(cxlog cx)
(cxlog cx1 cx2)
(cxsin cx)
(cxcos cx)
(cxcis cx)
(cxtan cx)
(cxasin cx)
(cxacos cx)
(cxatan cx)
(cxsinh cx)
(cxcosh cx)
(cxtanh cx)
(cxasinh cx)
(cxacosh cx)
(cxatanh cx)
(cxcis cx)

These procedures compute the usual transcendental functions. The cxexp procedure computes the base-e exponential of cx. The cxlog procedure with a single argument computes the natural logarithm of cx (not the base ten logarithm); (cxlog cx1 cx2) computes the base-cx2 logarithm of cx1. The cxsin, cxcos, cxtan, cxasin, cxacos, cxatan, The cxsin, cxcosh, cxtanh, cxasinh, cxacosh, and cxatanh procedures compute the sine, cosine, tangent, arcsine, arccosine, arctangent, and their hyperbolic analogues respectively. Finally, the cxcis function computes the compnum whose real part is the cosine of cx and whose imaginary part is the sine of cx.

See the corresponding section of R7RS-small for the underlying mathematical operations.

Implementations that use IEEE binary floating-point arithmetic should follow the relevant standards for these procedures.

(cxsqrt cx)

Returns the principal square root of cx.

(cxexpt cx1 cx2)

The cxexpt procedure returns cx1 raised to the power cx2. If cx1 is negative and cx2 is not an integer, the result may be a NaN, or may be some unspecified compnum. If cx1 is zero, then the result is zero.