C / C ++ language: scientific notation

Primarily used to represent floating point numbers, convenient expression

Scientific notation floating point number consists of three parts:

a + E + b

a: consists of a floating-point numbers, the integer if written, the compiler will automatically converted to floating point;

E: can be uppercase E, E may lower case;

b: the use of a power of a decimal integer side, this number may be negative, it can be positive, a positive number may be omitted and a positive sign;

例如:1.0e1

e后面跟的是10的指数(也就是1的10次方,e表示10次方)
1e1表示1×101,其实就是10。

1.0e-3

e后面跟的是10的指数(也就是1的10次方,e表示10次方)
1.0e-3表示1×10-3,其实就是0.001。
 
1.e-3
0 after the decimal point is omitted, the value represented by the value equal to 1.0e-3.
 
再例如
5e2f
其中f表示浮点数表示5×102,也就是500
 
========================================================================================================================
 
-1.56E+12 的常量表示法怎么计算?
理解为1.56的12次方的负数?也就是:-1560000000000
 
-1.56*10^12=-1560000000000
理解为-1.56*10的12次方-1560000000000
========================================================================================================================
 
 
    0.1101101111
+  0.0000000001
---------------  
    0.110110000
 
 
因为在任何区间内(比如1.0和2.0之间)都存在无穷多个实数,所以计算机浮点数不能表示区域内所有的值。浮点数往往只是实际值的近似。例如7.0可能以浮点数值6.99999存储。
 
解释
 
十进制转化为二进制的方法是 依次与2^(-n)作比较(n从1开始)
若大于该值则为1,且减去此值,否则为0;然后继续下一轮比较
 
举例说明:将0.842356转换成二进制,你会发现比较将会是无穷无尽的。
如果你截取到某位,必须做一些取舍。取舍的标准是:其后一位若为1则进1;后一位为0则不进。
若要截取9位,因为第10位为0,故不进位,则最终的结果为:0.110101111;
若要截取到8位,因为第9位为1,故要进位,则最终的结果为:0.110110000(即0.1101101111 + 0.0000000001)。
从这个例子可以看出十进制小数的转换成二进制时只是一个近似值。其实大部分浮点数保存在计算机中都只是一个近似值。至于是稍微大于原值还是稍微小于原值,要看截取时有无进位。
 
 
 
0.842356
 
0.110101111 0 1001001010010010001111100101101110000101011  截取第9位 第10位为0,所以不进位=0.110101111
 
0.11010111  1 01001001010010010001111100101101110000101011  截取第8位 第9位为1,所以进位  =0.110110000

Guess you like

Origin www.cnblogs.com/2018shawn/p/10942513.html