mathlab之floor,ceil,round,int以及fix函数
建议自己动手敲敲,网上很多人自己都没搞清楚然后好多错的。毕竟自己亲眼看到结果才有说服力。
以下是我亲眼见到的结果。
1.double floor(double)函数
floor()函数是常用的取整函数,特点是向下取整,无论正负取完整数值是变小的,eg : floor(2.3) = 2,floor(-3.3) = -4;
floor()函数可用来判断一个数是否为整数。比如:判断一个数是否为完全平方数
int charge(int n){
double m;
m = sqrt(n);
if(floor(m+0.5) == m)
return 1;
return 0;
}
注意由于m为浮点数,要注意浮点数运算时产生的误差。比如某次运算中整数1变成了0.999999,那么floor(m)就会等于0.所以可以加上0.5,以避免浮点误差带来的错误。另外这样也是用floor函数实现了四舍五入。
2.(double)ceil(double)函数
与floor函数相对应,ceil函数是向上取整的。无论正负取完整数值变大了。比如:ceil(2.4) = 3,ceil(-3.3) = -3.
3.(double)round(double)函数
round函数是四舍五入函数,也就是和我们数学习惯一样,无论正负先对绝对值四舍五入然后加上符号。比如:round(2.4) = 2,
round(3.5) = 4,round(-2.4) = -2,round(-3.5) = -4.
4.(int)int(double)函数
int函数是靠零取整函数,即无论正负直接取其整数部分,取整后绝对值会变小。比如:int(2.3) = 2,int(-3.4) = -3,int(2.7) = 2,int(-3.7) = -3.
5.fix函数
fix函数并不是mathlab里的函数,至少我用codeblocks和Vc++,math.h里是找不到这个函数的。应该是matlab里面的。
好啦,时间也不早啦,电脑也没电了。学完函数晚安喽。
mathlab之floor,ceil,round,int以及fix函数的更多相关文章
- MATLAB中取整函数(fix, floor, ceil, round)的使用
MATLAB取整函数 1)fix(x) : 截尾取整. >> fix( [3.12 -3.12]) ans = 3 -3(2)floor(x):不超过x 的最大整数.(高斯取整) & ...
- paper 68 :MATLAB中取整函数(fix, floor, ceil, round)的使用
MATLAB取整函数 1)fix(x) : 截尾取整. >> fix( [3.12 -3.12]) ans = 3 -3 (2)floor(x):不超过x 的最大整数.(高 ...
- matlab中fix, floor, ceil, round 函数的使用方法
转载: https://www.ilovematlab.cn/thread-91895-1-1.html Matlab取整函数有: fix, floor, ceil, round.具体应用方法如下: ...
- Math类的三个方法比较: floor() ceil() round()
public class Test { public static void main(String[] args) { double d1 = 3.4, d2 = 3.6; //正数 double ...
- ceil,floor,trunc,round,sign几个函数在SQL的使用方法
只是在oracle的环境下进行的几个数的测试,在这里只是举例说明,没有理论说明,抱歉. select ceil(1.8) from dual; --结果为1,向上取整select floor (1.8 ...
- MATLAB中floor、round、ceil、fix区别
Matlab取整函数有: fix, floor, ceil, round.具体应用方法如下:fix朝零方向取整,如fix(-1.3)=-1; fix(1.3)=1;floor,顾名思义,就是地板,所以 ...
- Matlab中的取整-floor,ceil,fix,round
FLOOR Round towards minus infinity. FLOOR(X) rounds the elements of X to the nearest integers toward ...
- php取整函数ceil,floor,round,intval函数的区别
开发过程中,遇到数据处理取整的时候,你会用哪个呢,小涛来介绍一下:PHP取整函数有ceil,floor,round,intval,下面详细介绍一下: 1.ceil — 进一法取整说明float cei ...
- [转]PHP取整函数:ceil,floor,round,intval的区别详细解析
我们经常用到的PHP取整函数,主要是:ceil,floor,round,intval. 1.ceil -- 进一法取整 说明float ceil ( float value ) 返回不小于 value ...
随机推荐
- cocos2d-x for android配置 & 运行 Sample on Linux OS
1.从http://www.cocos2d-x.org/download下载稳定版 比如cocos2d-x-2.2 2.解压cocos2d-x-2.2.zip,比如本文将其解压到 /opt 目录下 3 ...
- MVC 导出Excel 的其中一方法(View导出excel)
场景:mvc下导出excel 思路:使用View导出excel 步骤: 1.导出标签添加事件 $("#export_A").click(function(){ //省略代码.... ...
- 解决eclipse端口占用问题
在eclipse中开启tomcat服务器时报错:端口已被占用. 这是因为在tomcat开启的状态下,eclipse异常关闭,导致tomcat一直占用端口. 解决方法 在cmd窗口中输入命令-- net ...
- 11. KVC And KVO
1. KVC And KVO 的认识 KVC/KVO是观察者模式的一种实现 KVC全称是Key-value coding,翻译成键值编码.顾名思义,在某种程度上跟map的关系匪浅.它提供了一种使用 ...
- To Learn
1. Hybrid:Ionic.Cordova.AngularJS等框架 webView,处理H5 2. View.ViewGroup android.view.View public class ...
- PHP两种基础的算法:冒泡、快速排序法》》》望能够帮助到大家
首先扯个淡@@@@@@@@@ 算法是程序的核心,一个程序的好坏关键是这个程序算法的优劣. 冒泡排序法 原理:在要排序的一组数中,对当前还未排好的序列,从前往后对相邻的两个数依次进行比较和调整,让较大的 ...
- linux 如何查找io的进程
[root@NB ok]# echo chenlin|base64;echo Y2hlbmxpbgo= [root@NB ok]# yum search iotop Loaded plugins: f ...
- spring configuration 注解
org.springframework.context.annotation @annotation.Target({ElementType.TYPE}) @annotation.Retention( ...
- PLSQL操作excel
一.plsql数据库操作: 删除数据前备份一张表: create table plat_counter_def_bf as select * from plat_monitor_counter_def ...
- Startcom SSL证书申请 IIS设置 配置 攻略
申请具体参考:http://www.cnblogs.com/yibinboy/p/6137426.html 制作要导入服务器IIS上的证书. 点击控制面板的左上角的TOOL BOX,然后点击Creat ...