Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <cmath>
- using namespace std;
- //вариант 20:
- //arctg(x), |x| < = 1
- void calc(double x, double Epsilon) {
- double cm1 = -1, c1 = 1, c2 = 2, c3 = 3;
- double previous_value;
- double result;
- int n = 0;
- _asm {
- finit // инициализация сопроцессора
- fld x // s0 = -1
- fst result // result = x
- fstp previous_value // previous_value = x
- begin_loop:
- fld n //st0 = n
- fmul c2 //st0 = 2n
- fadd c3 //st0 = 2n+3
- fld n //st0 = n, st1 = 2n+3
- fmul c2
- fadd c1 //st0 = 2n+1, st1 = 2n+3
- fdivp st(1), st //st0 = (2n + 1)/(2n + 3)
- fmul cm1
- fmul x
- fmul x //st0 = -x^2*(2n + 1)/(2n + 3)
- fmul previous_value //st0 = Cn * (-x^2*(2n + 1)/(2n + 3)) == Cn+1
- fadd result //st0 = Cn * (-x^2*(2n + 1)/(2n + 3)) + сумма предыдущих членов
- fstp result // result = сумма предыдущих членов + текущий
- fld n //st0 = n
- fadd c1 //st0 = n + 1
- fstp n // n = n + 1
- fld previous_value //st0 = previous_value
- fabs // st0 = |previous_value|
- fld Epsilon // st0 = Epsilon, st1 = |previous_value|
- fcomp st(1) // сравнение Epsilon и текущего члена
- fstsw ax //записываем значение в регистр ax
- ja end_of_code
- jb begin_loop
- end_of_code:
- }
- cout << "Result: "<< result <<"\nn: " << n + 1 << "\nDelta: " << abs(atan(x) - result);
- }
- int main() {
- cout << "x: ";
- double x;
- cin >> x;
- if (abs(x) > 1)
- {
- cout << "Incorrect Data: |x| > 1" << endl;
- return 0;
- }
- cout << endl << "Epsilon: ";
- double Epsilon;
- cin >> Epsilon;
- cout << endl;
- calc(x, Epsilon);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement