浮点数
浮点数是由一个可选符号、一个或多个数字、一个小数点(可选)后跟一个或几个数字、可选后跟字母
e
或
E
、可选后跟符号、可选后跟一个或者多个数字组成的数字。
没有小数点的数字是
整数.
[ sign ] digit [ digit [ ... ] ] . [ { digit [ digit [ ... ] ] } ] [ { e | E } [ sign ] digit [ digit [ digit [ ... ] ] ]
-
sign
: +
or -
, if the sign is missing, it is presumed to be +
.
-
digit
: 0
through 9
.
-
.
: indicates the number is a floating point number rather than an 整数.
-
e
or E
: indicates the number has an exponent. The case is ignored. There must be at least one digit after the E
or e
, optionally preceded by a sign.
At least one digit must appear before the decimal point. Note that while no digits are required after the decimal point, at least one digit
must follow an
E
or
e
if it is used.
If there is no decimal point and no exponant, then the number will be interpreted as an
integer.
The following are all valid floating-point numbers:
0.0 +0.0 0. -0.0 0.0e+1 0.0e-1 0.e+0 0.0e0 0.0e-0 -0.0e-0 (all are the same 0.0) 0.7 -0.3 1.0 -1. 1. -1.0 37.16 -40.33 +1.5 -12.34 3.14159267 1.39e5 1.7E-3
The following are all the same:
1000000.0 1.E+7 1e7 1.0e7 10.0e6 0.100E8 10000000.0E-1
Gambas provides two different floating-point types:
Floating-Point
|
Description
|
Default value
|
Size in memory
|
Single
|
-1.7014118E-38 .. +1.7014118E+38
|
0.0
|
4 bytes
|
Float
|
-8.98846567431105E-307 .. +8.98846567431105E+307
|
0.0
|
8 bytes
|
See also