Skip to content

Instantly share code, notes, and snippets.

@proelbtn
Last active April 27, 2019 06:15
Show Gist options
  • Save proelbtn/3a79e8697fb7a86509143ffc402017bd to your computer and use it in GitHub Desktop.
Save proelbtn/3a79e8697fb7a86509143ffc402017bd to your computer and use it in GitHub Desktop.
e^xの近似
#include <stdio.h>
#include <stdint.h>
int main() {
double ans, index;
printf("index = ");
scanf("%lf", &index);
ans = 1;
for (int i = 20; i >= 1; i--) ans = 1 + index * ans / i;
printf("e^{%lf} = %.20lf\n", index, ans);
}
@proelbtn
Copy link
Author

i == 100でやった時

$ ./a.out
index = -5
e^{-5.000000} = 0.00673794699908381034

@proelbtn
Copy link
Author

だいたい100次で精度打ち切りな感じがある。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment