Formal comment #122 (enhancement)
Allow real->single and real->double to convert complex numbers
Reported by: Alan Watson
Component: arithmetic
Version: 5.91
The "real->single" and "real->double" procedures are restricted
to real numbers. Why not rename them "->single" and "->double"
and allow them to operate on complex numbers too?
RESPONSE:
When given a complex number that is not real, the result would
presumably be an inexact complex number whose real and imaginary
parts are inexact reals that best approximate the best possible
IEEE single and double precision approximations to the real and
imaginary parts of the original argument.
The editors decided that the utility of the suggested extension
to complex numbers does not justify their inclusion in the R6RS
when they can be defined so easily in terms of real->single and
real->double:
(define (->single z)
(make-rectangular (real->single (real-part z))
(real->single (imag-part z))))
(define (->double z)
(make-rectangular (real->double (real-part z))
(real->double (imag-part z))))
The editors also decided that the utility of real->single and
real->double does not justify their inclusion in the R6RS,
since their effect can be achieved by storing a real number
into a bytes object:
(define (real->single x)
(let ((b (make-bytes 4)))
(bytes-ieee-single-native-set! b 0 x)
(bytes-ieee-single-native-ref b 0)))
(define (real->double x)
(let ((b (make-bytes 8)))
(bytes-ieee-double-native-set! b 0 x)
(bytes-ieee-double-native-ref b 0)))
The IEEE floating point operations on bytes objects were added
to the draft R6RS several months after the real->single and
real->double procedures were added, and the editors did not
realize the real->single and real->double procedures had
become so easy to define until they considered this formal
comment.