網站首頁 編程語言 正文
包含頭文件
#include<cmath>
1、fabs(double x)
對double型變量取絕對值
#include<iostream>
using namespace std;
#include<cmath>
int main()
{
double d=-3.14;
printf("%.2f\n",fabs(d));
return 0;
}
2、floor(double x)ceil(double x)
用于double型變量,返回類型也為double
向下取整:floor
向上取整:ceil
#include<iostream>
using namespace std;
#include<cmath>
int main()
{
double d1=-3.14;
double d2=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 x,double n)
返回x的n次方
#include<iostream>
using namespace std;
#include<cmath>
int main()
{
double d=pow(2.0,3.0);
printf("%f\n",d);
return 0;
}
8.000000
4、sqrt(double x)
返回double型變量的算術平方根
#include<iostream>
using namespace std;
#include<cmath>
int main()
{
double d=sqrt(3.0);
printf("%f\n",d);
return 0;
}
5、log(double x)
返回以自然對數e為底的對數
#include<iostream>
using namespace std;
#include<cmath>
int main()
{
double d=log(exp(1));//exp(1)表示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);//更精確
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)
參數要求是弧度制
也有對應的反函數
#include<iostream>
using namespace std;
#include<cmath>
const double PI=acos(-1.0);//因為cos(pi)=-1
int 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)
將double型變量四舍五入取整,返回也是double
原文鏈接:https://blog.csdn.net/qq_57987156/article/details/124366284
相關推薦
- 2023-01-31 C#實現批量壓縮和解壓縮的示例代碼_C#教程
- 2022-11-26 使用HttpClient增刪改查ASP.NET?Web?API服務_實用技巧
- 2022-10-01 python3中_from...import...與import?...之間的區別詳解(包/模塊)_
- 2022-04-17 python中lambda匿名函數詳解_python
- 2023-01-02 Android?Map數據結構全面總結分析_Android
- 2022-04-18 taro 中設計稿尺寸相關問題,以及自適應頁面寫法
- 2022-04-27 詳解linux里的backlog參數_Linux
- 2022-06-12 C#泛型接口的協變和逆變_C#教程
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支