implementation comments Bradley Lucier (09 Aug 2026 20:57 UTC)
Re: implementation comments Peter McGoron (09 Aug 2026 22:51 UTC)
Re: implementation comments Bradley Lucier (10 Aug 2026 15:10 UTC)
Re: implementation comments Peter McGoron (12 Aug 2026 03:53 UTC)

implementation comments Bradley Lucier 09 Aug 2026 20:57 UTC

I cloned the github repository and make my comments from that; apologies
if they happen not to be relevant for whatever reason.

1.  I think you should replace

(define (sinh z)
   (cond
     ((eqv? z 0) 0)
     ((real? z) (flsinh (flonum z)))
     (else
       (make-rectangular (* (flsinh (real-part z))
                            (cos (imag-part z)))
                         (* (flcosh (real-part z))
                            (sin (imag-part z)))))))

with

(define (sinh z)
   (cond
     ((eqv? z 0) 0)
     ((real? z) (flsinh (flonum z)))
     (else
       (make-rectangular (* (sinh (real-part z))
                            (cos (imag-part z)))
                         (* (cosh (real-part z))
                            (sin (imag-part z)))))))

because you don't know that the real-part of z is a flonum.

2.  I think you should replace

(define (cosh z)
   (cond
     ((eqv? z 0) 1)
     ((real? z) (flcosh (flonum z)))
     (else
       (let ((x (flonum (real-part z)))
             (y (imag-part z)))
         (make-rectangular (* (flcosh x) (cos y))
                           (* (flsinh x) (sin y)))))))

with

(define (cosh z)
   (cond
     ((eqv? z 0) 1)
     ((real? z) (flcosh (flonum z)))
     (else
       (let ((x (real-part z))
             (y (imag-part z)))
         (make-rectangular (* (cosh x) (cos y))
                           (* (sinh x) (sin y)))))))

because if (real-part z) is exact zero and (sinh 0) returns exact zero
and multiplying (* 0 anything) returns exact zero, then the result will
have exact zero imaginary part:

 > (cosh +1i)
.5403023058681398

3. In the definition of casin, replace flasinh by asinh, otherwise if
csqrt can return an exact answer given an exact argument, then this can
happen:

 > (define (casin z)
      (let ((x (real-part z))
            (s:1-z (csqrt (- 1 z)))
            (s:1+z (csqrt (+ 1 z))))
        (make-rectangular (atan x (real-part (* s:1-z s:1+z)))
                          (flasinh (imag-part (* (conjugate s:1-z)
                                                 s:1+z))))))
 > (define csqrt sqrt)
 > (casin 5/4)
*** ERROR IN casin, (stdin)@9.26-10.57 -- (Argument 1) FLONUM expected
(flasinh -3/4)

4.  Similarly for %acosh:

 > (define (%acosh z)
   (let* ((x (real-part z))
          (y (imag-part z))
          (sqrt:z-1 (csqrt (- z 1)))
          (sqrt:z+1 (csqrt (+ z 1))))
     (make-rectangular (flasinh (real-part (* (conjugate sqrt:z+1)
                                              sqrt:z-1)))
                       (* 2 (atan (imag-part sqrt:z-1)
                                  (real-part sqrt:z+1))))))
 > (%acosh 5/4)
*** ERROR IN %acosh, (stdin)@19.23-20.57 -- (Argument 1) FLONUM expected
(flasinh 3/4)