sin x in Visual C++

Batorek 1 Reputation point
2021-12-29T23:57:36.397+00:00

See https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/sin-sinf-sinl?view=msvc-170 .
There wrote what do You doing with him . i am interesing Where do Microsoft get sine x in Visual C++?

Developer technologies C++
{count} votes

1 answer

Sort by: Most helpful
  1. Minxin Yu 13,501 Reputation points Microsoft External Staff
    2021-12-30T03:04:13.62+00:00

    Hi, @Batorek

    sin( ) is a function: _Check_return_ double __cdecl sin(_In_ double _X);
    You could also try to write sin().
    For example:

    #include<iostream>  
    #include<math.h>  
      
    double MySin(double x)  
    {  
    	double s, t;  
    	int n;  
      
    	t = x; n = 1; s = x;  
    	do {  
    		n = n + 2;  
    		t = -t * x * x / (n - 1) / n;  
    		s = s + t;  
    	} while (fabs(t) >= 1e-7);  
    	return s;  
    }  
    int main()  
    {  
    	//  30°==0.52359877559829887307710723054658  
    	std::cout << MySin(0.52359877559829887307710723054658)<<std::endl;  
    	std::cout << sin(0.52359877559829887307710723054658)<<std::endl;  
        //out put :0.5  
    }  
    

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.