Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- # define PI 3.1415926
- double currentPow = 1;
- int currentPowIndex = 0;
- double currentFactNumber = 1;
- int currentFactNumberIndex = 0;
- double cached_pow(double number, int powIndex) {
- for (int i = currentPowIndex; i < powIndex; i++) {
- currentPow *= number;
- }
- currentPowIndex = powIndex;
- return currentPow;
- }
- double cached_fact (int factNumberIndex) {
- for (int i = factNumberIndex; i > currentFactNumberIndex; i--) {
- currentFactNumber *= i;
- }
- currentFactNumberIndex = factNumberIndex;
- return currentFactNumber;
- }
- int main() {
- double x = 120.0 / 180.0 * PI;
- double sinx = x;
- int sign = 1;
- double nextValue = 0.0;
- //877 iterations
- for (int i = 1; 0 != (nextValue = (cached_pow(x, 2*i + 1) / cached_fact(2*i + 1))); i++) {
- sign *= -1;
- sinx += sign * nextValue;
- }
- cout << sinx << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement