Hi,
I think I found a bug/inconsistency/regression in ctan(3) introduced
somewhere after 6.1 release. Originally observed in math/R
(https://marc.info/?l=openbsd-ports&m=150728711530471&w=2) the behavior can be
reproduced with following C program:
--8<---------------------------------------------------------------------------
#include <complex.h>
#include <math.h>
#include <stdio.h>
int
main(int argc, char *argv[])
{
// http://en.cppreference.com/w/c/numeric/complex/ctan
double complex z = ctan(1); // behaves like real tangent along the
real line
printf("tan(1+0i) = %f%+fi ( tan(1)=%f)\n", creal(z), cimag(z), tan(1));
// http://en.cppreference.com/w/c/numeric/complex/ctan
double complex z2 = ctan(I); // behaves like tanh along the imaginary
line
printf("tan(0+1i) = %f%+fi (tanh(1)=%f)\n", creal(z2), cimag(z2),
tanh(1));
double complex z3 = ctan(1+1000I);
printf("tan(1+1000i) = %f%+fi\n", creal(z3), cimag(z3));
}
--8<---------------------------------------------------------------------------
cc ctan.c -lm
./a.out
The correct solution for the z3 example is "0+1i".
On a -current amd64 system (both clang and gcc give identical results):
$ ./a.out
tan(1+0i) = 1.557408+0.000000i ( tan(1)=1.557408)
tan(0+1i) = 0.000000+0.761594i (tanh(1)=0.761594)
tan(1+1000i) = -nan-nani
On 6.1 release amd64 with gcc 4.2.1:
$ ./a.out
tan(1+0i) = 1.557408+0.000000i ( tan(1)=1.557408)
tan(0+1i) = 0.000000+0.761594i (tanh(1)=0.761594)
tan(1+1000i) = 0.000000-nani
This result seems to be "sufficiently different from wrong" that R is somehow
able to return the correct solution on 6.1 release:
R> (z <- tan(1+1000i))
[1] 0+1i
On a Debian 9.1 Linux with gcc 6.3.0:
$ ./a.out
tan(1+0i) = 1.557408+0.000000i ( tan(1)=1.557408)
tan(0+1i) = 0.000000+0.761594i (tanh(1)=0.761594)
tan(1+1000i) = 0.000000+1.000000i
Ideas, pointers and solutions are highly appreciated.
Best regards,
Ingo