关于求绝对值的问题
来源:互联网 发布:mac sass安装出错 编辑:程序博客网 时间:2024/05/18 20:10
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;// --></script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>
当用abs求绝对值时,需要注意不同的数据类型调用不同的API函数,其中abs、labs、fabs分别对应整型、长整型、浮点型。假如对浮点数用了abs得到的将是强制转换后的整型。下面是MSDN上的例子:
Example
/* ABS.C: This program computes and displays * the absolute values of several numbers. */#include <stdio.h>#include <math.h>#include <stdlib.h>void main( void ){ int ix = -4, iy; long lx = -41567L, ly; double dx = -3.141593, dy; iy = abs( ix ); printf( "The absolute value of %d is %d/n", ix, iy); ly = labs( lx ); printf( "The absolute value of %ld is %ld/n", lx, ly); dy = fabs( dx ); printf( "The absolute value of %f is %f/n", dx, dy );}
Output
The absolute value of -4 is 4The absolute value of -41567 is 41567The absolute value of -3.141593 is 3.141593
更多技术文章请参看施昌权的个人网站: http://www.joyvc.cn
- 关于求绝对值的问题
- 求绝对值的函数模版
- 求浮点数的绝对值
- 1035 求整数的绝对值
- 求绝对值最小的数
- 求绝对值最小的数
- 求绝对值最小的数
- 求绝对值最小的数
- 求绝对值的方法汇总
- 求一整数的绝对值
- 求一整数的绝对值
- 求两个数的绝对值
- 求一个数的绝对值
- 求一个数的绝对值
- 求一个数的绝对值
- 求一个数的绝对值
- 求绝对值
- 求绝对值
- 概要设计的方法
- 日语流行口语极短句2
- SQL综合应用学习
- 微软平台嵌入式开发技术评析
- 关于memset函数的用法
- 关于求绝对值的问题
- 如何修复SQLSERVER"置疑"之(二)
- 定制个性的对话框窗口类
- 对所有表进行类似处理
- 使用GDI+在内存中转换图片类型
- 瞬间的牵手,留下了永恒的怀念!
- sysinfo.py (获取系统信息)
- 找SQL表的主键
- 银行业务模拟系统