You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.0 KiB

25 years ago
  1. // tan().
  2. // General includes.
  3. #include "cl_sysdep.h"
  4. // Specification.
  5. #include "cl_complex.h"
  6. // Implementation.
  7. #include "cl_C.h"
  8. #include "cl_real.h"
  9. const cl_N tan (const cl_N& x)
  10. {
  11. // Methode:
  12. // x reell -> (/ (sin x) (cos x))
  13. // x = a+bi -> (/ (complex (* (sin a) (cosh b)) (* (cos a) (sinh b)))
  14. // (complex (* (cos a) (cosh b)) (- (* (sin a) (sinh b)))) )
  15. if (realp(x)) {
  16. DeclareType(cl_R,x);
  17. var cl_cos_sin_t trig = cl_cos_sin(x);
  18. return trig.sin / trig.cos;
  19. } else {
  20. DeclareType(cl_C,x);
  21. // x=a+bi
  22. var const cl_R& a = realpart(x);
  23. var const cl_R& b = imagpart(x);
  24. var cl_cosh_sinh_t hyp_b = cl_cosh_sinh(b); // cosh(b), sinh(b) errechnen
  25. var cl_cos_sin_t trig_a = cl_cos_sin(a); // cos(a), sin(a) errechnen
  26. return
  27. complex_C(trig_a.sin * hyp_b.cosh, // sin(a)*cosh(b)
  28. trig_a.cos * hyp_b.sinh // cos(a)*sinh(b), nicht Fixnum 0
  29. )
  30. / complex(trig_a.cos * hyp_b.cosh, // cos(a)*cosh(b)
  31. - (trig_a.sin * hyp_b.sinh) // -sin(a)*sinh(b)
  32. );
  33. }
  34. }