Small code commonly used in C language

Source: Internet
Author: User
Pi

Tan (PI/4) =1 and Pi=4*arctan (1)

The inverse tangent function arctan () is represented in the C language as Atan (), and the code to ensure the accuracy of pi is as follows:

  

Const Double 4.0 * ATAN (1.0);

Rounded

Sometimes we need to avoid floating-point error by rounding. If 100 after the radical operation should be 10, but the SQRT function is "accidentally" to 99.999, in order to avoid affecting our program, need to be rounded. The floor () function is used here to return the integer part of a number, which is rounded down. The rounding code is as follows:

  

0.5 );    // rounding x to get y

Small code commonly used in C language

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.