In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Today, I would like to share with you the relevant knowledge points about how to use C++ 's math function. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.
Include header file
# include1, fabs (double x)
Take the absolute value of the variable of double type
# includeusing namespace std;#includeint main () {double dazzle color 3.14; printf ("% .2f\ n", fabs (d)); return 0;} 2, floor (double x) ceil (double x)
For a variable of double type, and the return type is also
Round down: floor
Round up: ceil
# includeusing namespace std;#includeint main () {double D1 colors 3.14; double d2 colors 3.14; printf ("% .0f% .0f\ n", floor (D1), ceil (D1)); printf (".0f% .0f\ n", floor (D2), ceil (D2)); return 0;}
-4-3
3 4
3. Pow (double xperfine double n)
Returns x to the nth power
# includeusing namespace std;#includeint main () {double d=pow (2.0 focus 3.0); printf ("% f\ n", d); return 0;}
8.000000
4. Sqrt (double x)
Returns the arithmetical square root of a variable of the multiplier type
# includeusing namespace std;#includeint main () {double d=sqrt (3.0); printf ("% f\ n", d); return 0;} 5, log (double x)
Returns the logarithm based on the natural logarithm e
# includeusing namespace std;#includeint main () {double d=log (exp (1)); / / exp (1) means e printf ("% f\ n", d); double d1=log10 (10.0); printf ("% f\ n", D1); double d2=log2 (2); printf ("% f\ n", D2); double d3=log1p (10); / / more precise printf ("% f\ n", D3); double d4=log (10) Printf ("% f\ n", d4); return 0;}
1.000000
1.000000
1.000000
2.397895
2.302585
6. Sin (double x) cos (double x) tan (double x)
The parameter requirement is Radian system.
There are also corresponding inverse functions.
# includeusing namespace std;#includeconst double PI=acos; / / because cos (pi) =-1int main () {double d=sin (PI/4); printf ("% f\ n", d); double d1=cos (PI/4); printf ("% f\ n", D1); double d2=tan (PI/4); printf ("% f\ n", D2); double d3=asin (1); printf ("% f\ n", D3) Double d4=atan (1); printf ("% f\ n", d4); return 0;} 7, round (double x)
Round the round variable, and return double.
That's all of the article "how to use C++ 's math function". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.