Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- //exp(x) evaluation
- int main() {
- double x = -1000;
- bool invert = (x < 0);
- if (invert) {
- x = -x;
- }
- double res = 0;
- double pw = 1;
- double fac = 1;
- for (int i = 0; i < 100; ++i) {
- res += pw/fac;
- fac *= (i+1);
- pw *= x;
- }
- if (invert) {
- res = 1 / res;
- x = -x;
- }
- printf("exp(%lf) = %lf\n", x, res);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement