38_euler_formula.c 506 B

123456789101112131415161718192021222324252627
  1. #include <stdio.h>
  2. #include <mpc.h>
  3. #include <mpfr.h>
  4. #define PREC 256
  5. int main()
  6. {
  7. mpc_t rx;
  8. mpc_t ipi4;
  9. mpfr_t pi;
  10. mpfr_set_default_prec(PREC);
  11. mpc_init2(rx, PREC);
  12. mpc_init2(ipi4, PREC);
  13. mpfr_init(pi);
  14. mpfr_const_pi(pi, MPFR_RNDD);
  15. mpc_set_fr(ipi4, pi, MPC_RNDDD);
  16. mpc_mul_i(ipi4, ipi4, 1, MPC_RNDDD);
  17. mpc_div_ui(ipi4, ipi4, 4, MPC_RNDDD);
  18. mpc_exp(rx, ipi4, MPC_RNDDD);
  19. printf("Computed value of e^(i*pi/4) is ");
  20. mpc_out_str(stdout, 10, 0, rx, MPC_RNDDD);
  21. printf("\n");
  22. return 0;
  23. }