Fermat618's Blog

Happy coding

整数,小数;整型,浮点型

Fermat618 posted @ 2013年10月29日 17:26 in 未分类 , 1724 阅读

这四个概念,前面两个,表示数学中的整数,小数;后面两个,表示计算机中相应的表示。

在C语言中,整数一般用整型表示,而小数一般用浮点型来表示。先学C语言的人往往容易对此有固定的印象。同时会觉得浮点型表示的数都是不精确的。然而,这个印象是不准确的

浮点型数也可以表示整数,而且在整数不是非常大的情况下,这种表示是精确的。对浮点型表示的整数,进行加、减、乘操作,得到的仍是精确的结果。仍可以用来表示长度,表示数组下标等。

在很久以前,浮点数的计算很慢。然后,现在的发展下浮点数的计算已经快多了。而对于脚本语言来说,速度往往不是那么的重要。Cpython 的运行要比相应的C语言慢100倍左右。这时,使用整型来表示整数的速度优势完全没有了,而空间优势也不大。所以,在脚本语言中区分整型和浮点型已经是件很尴尬的事。而 Javascript 的数值类型已经默认只有一个,就是浮点型。Matlab 的默认类型也已经是浮点型。Python 3 中 int 已经默认可以为任意大的整数,算是给整型的存在又找回了点面子。

 

CBSE Sample Paper 说:
2022年9月22日 02:13

All the Central Board of Secondary Education Students of Chennai Scheme, Delhi Scheme and All India Scheme can download the Sample Paper Suggestions with Model Papers along with Previous Years old Exam Solved Question Bank for all Languages & Subjects of the Course. CBSE Sample Paper All the Central Board of Secondary Education Students of Chennai Scheme, Delhi Scheme and All India Scheme can download the Sample Paper Suggestions with Model Papers along with Previous Years old Exam Solved Question Bank for all Languages & Subjects of the Course.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter