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 ...
随机推荐
- DevExpress 关于alertControl 改变其大小
private void alertControl1_FormLoad(object sender, DevExpress.XtraBars.Alerter.AlertFormLoadEventArg ...
- IDEA 配置 tomcat的数据源
1.F4打开module setting面板,找到facets 配置项,这个配置项非常重要,里面可配置tomcat加载的web.xml和context.xml文件所在的路径,部署的时候IDEA会自动读 ...
- git 修改注释信息
1. push 之前 先看看自己提交过多少次,然后执行 git rebase -i HEAD~数字(你要修改你的第几次提交) 接下来执行,修改注释 git commit --amend 修改完注释之后 ...
- disconf搭建
简介: Distributed Configuration Management Platform(分布式配置管理平台) 它是百度的一套完整的基于zookeeper的分布式配置统一解决方案,具有如下特 ...
- 【纯css】左图右文列表,左图外框宽度占一定百分比的正方形,右上下固定,右中自动响应高度。支持不规则图片。
查看演示 <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF- ...
- iOS多线程笔记
在iOS开发中,有三种多线程处理方式: 1. 利用NSThread 2. NSOperation和NSOperationQueue 3. 利用GCD(Grand Central Dispatch) 使 ...
- C 标准库系列之float.h
float.h 内部主要包含了一系列的浮点数宏.指明可移植程序必要的常量:浮点数格式一般为Spxbe;其中S表示+-:p表示底数.b表示基数如2.8.10.16等进制,e为指数标识E或e: 在一般情况 ...
- C#远程时间同步助手软件设计
C#远程时间同步助手软件设计 本程序才C#语言开发,实现远程时间同步功能,可以将本地时间每隔一段时间与时间服务器时间进行同步!不足之处还望见谅! 软件开发环境:Visual Studio 2010 软 ...
- phpcms V9 整合 Discuz! X2 教程
整合原理: UCenter 作服务端:phpsso 与 Discuz! 分别作 UCenter 的客户端应用:phpsso 与 Discuz! 通过 UCenter 发生交互. phpcms 通过 p ...
- Android学习资源整理
官方文档:https://developer.android.com/guide/index.html (万万没想到居然有中文) 网友整理的学习笔记,挺不错的 http://www.runoob.co ...