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

cowan
2016-06-19 07:12:17
1history
source

A compnum is a general complex number whose real-part and imag-part are both flonums. The following procedures should be in a different library from the flonum procedures.

Compnum operations paralleling R6RS flonum library

The R6RS-specific integer division procedures have been removed, as have the condition types.

This section uses cx, cx1, cx2, etc., as parameter names for compnum arguments, and icx as a name for integer-valued compnum arguments, i.e., compnums for which the integer? predicate returns true.

(compnum? obj)procedure 

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

(compnum x)procedure 

Returns the best compnum representation of x.

The value returned is a compnum that is numerically closest to the argument.

Note: If compnums are represented in binary floating point, then implementations should break ties by preferring the floating-point representation whose least significant bit is zero.

(cxmake-rectangular fl1 fl2 ) procedure 

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

(cxmake-polar fl1 fl 2 ) procedure 

The value returned is a compnum whose magnitude is the flonum fl1 and whose angle is the flonum fl2

(cx=? cx1 cx2 cx3 ...)procedure 

This procedure returns #t if its arguments are equal.

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

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 or the imaginary parts or both is an infinity, and cxnan? tests whether either the real part or the imaginary part or both is a NaN.

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

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 ...)procedure 
(cx/ cx)procedure 

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.)

(cx- +inf.0 +inf.0)      ⇒  +nan.0

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

(cxreal-part cx)procedure 

This procedure returns the real part of cx.

(cximag-part cx)procedure 

This procedure returns the imaginary part of cx.

(cxangle cx)procedure 

This procedure returns the angle of cx.

(cxabs cx)procedure 
(cxmagnitude cx)procedure 

These procedures return the absolute value (magnitude) of cx.

(cxexp cx)procedure 
(cxlog cx)procedure 
(cxlog cx1 cx2)procedure 
(cxsin cx)procedure 
(cxcos cx)procedure 
(cxtan cx)procedure 
(cxasin cx)procedure 
(cxacos cx)procedure 
(cxatan cx)procedure 
(cxsinh cx)procedure 
(cxcosh cx)procedure 
(cxtanh cx)procedure 
(cxasinh cx)procedure 
(cxacosh cx)procedure 
(cxatanh cx)procedure 
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. (cxatan[h] cx1 cx2) computes the (hyperbolic) arc tangent of cx1/cx2.

See report section on “Transcendental functions” for the underlying mathematical operations. In the event that these operations do not yield a real result for the given arguments, the result may be a NaN, or may be some unspecified compnum.

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

(cxsqrt cx)procedure 

Returns the principal square root of cx. For negative arguments, the result may be a NaN or some unspecified compnum.

(cxexpt cx1 cx2)procedure 

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

C99 <complex.h> constants

The following constants are defined in terms of the constants of the <math.h> header of ISO/IEC 9899:1999 (C language).

Scheme name

C name

Comments

cx:i

I

0+1i as a compnum

Compnum procedures from <complex.h>

Scheme name

C signature

Comments

cxconjugate

double complex conj(double complex)

complex conjugate

cxexp

double complex cexp(double complex)

-

||cxprojection||double complex cproj(double complex)||projects to Riemann sphere

The following are general complex number functions, not just for compnums.

(cis z)

Returns eiz, a complex number whose real part is cos z and whose imaginary part is sin z.

(signum z)

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. As a consequence of this definition, negative real numbers return -1, positive real numbers return 1, and zero returns zero.