expcos.cpp 587 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Do the exponential cosine function.
  2. #include "stdafx.h"
  3. #include "defs.h"
  4. void
  5. eval_expcos(void)
  6. {
  7. push(cadr(p1));
  8. eval();
  9. expcos();
  10. }
  11. void
  12. expcos(void)
  13. {
  14. save();
  15. p1 = pop();
  16. push(imaginaryunit);
  17. push(p1);
  18. multiply();
  19. exponential();
  20. push_rational(1, 2);
  21. multiply();
  22. push(imaginaryunit);
  23. negate();
  24. push(p1);
  25. multiply();
  26. exponential();
  27. push_rational(1, 2);
  28. multiply();
  29. add();
  30. restore();
  31. }
  32. #if SELFTEST
  33. static char *s[] = {
  34. "expcos(x)",
  35. "1/2*exp(-i*x)+1/2*exp(i*x)",
  36. };
  37. void
  38. test_expcos(void)
  39. {
  40. test(__FILE__, s, sizeof s / sizeof (char *));
  41. }
  42. #endif