01012 01012 =0*23 + 1*22 + 0*21 + 1*20
:
11.01012 =1*21+ 1*20 + 0*2-1 + 1*2-2 + 0*2-3 + 1*2-4
, n ( ) (102)n = 2n. ( ) 2n.
(floating point), .
x x=s*m*2p. s . m , p .
10- , :
1 4 5
. 0, , 1 . , , m, 1≤m<2. . , 1.01012, 10.1012 0.101012 , 1.01012. , , - . 101012.
( ) , . 1.01012, 10.1012 0.101012 0, 1 -1, . , . , . , , . , . , . . k , 2k , k , . , . . , .
: (, , , , , ) . , . , .
|
|
: 2n, n, n . 2n n , . , , .
:
11.0112 0.110112 . 1.10112, 1, 11.0112=1.10112*(102)1. 1.10112 , -1, 0.110112 =1.10112*(102)-1. 1, 2 , 2:
0.110112 = 0.0110112* (102)1.
(, 5 ), 0.01102* (102)1. -
1.10112*(102)1 + 0.0110112*(102)1 = (1.10112 + 0.0110112)*(102)1 ≈ (1.10112 + 0.01102)*(102)1 =10.00012* (102)1 ≈ 1.00002*(102)2
1.00001112*(102)2.
, , . , , , , . , , , .
(plain text) . , 10 E ( Exponent ). , 1.5E14, 0.31E-7. E , . e, . 3e2 , . .
double. , 1.5, -17E2, 0.0. float, f ( float): 1.5f, -17E2f, 0.0f.
float
Float.MIN_VALUE - 2-149
Float.MAX_VALUE - (2-2-23)∙2127
double -
Double.MIN_VALUE - 2-1074
Double.MAX_VALUE - (2-2-52)∙21023.
IEEE 754 *
*
? IEEE 754 ( IEC 60559:1989), . , : real*4, real*8 real*10. 4, 8 10 , . Java real*4 float, real*8 double. real*10 PASCAL, Java .
|
|
r s, m 2p-d:
r=s*m*2p-d.
p . . d, , . pmax, . , d= (pmax+1)/2-1.
real*4: pmax = 255, d= 127.
real*8: pmax = 2047, d= 1023.
real*10: pmax =32767, d=16383.
, 1≤m<2. . , 1. 2 , 2.
IEEE 754 1 pmax-1 . . 0, . . pmax , . .
:
1 | 2 | 3 | 4 | 8 | 9 | 10 | ||
real*4 | sppp pppp | pmmm mmmm | mmmm mmmm | mmmm mmmm | ||||
real*8 | sppp pppp | pppp mmmm | mmmm mmmm | mmmm mmmm | mmmm mmmm | |||
real*10 | sppp pppp | pppp pppp | 1mmm mmmm | mmmm mmmm | mmmm mmmm | mmmm mmmm | mmmm mmmm |
s ; p , m . , , . real*4 (float) real*8 (double) , , , 23 52 , , 24 53 . real*10 , 64 . real*4 8 , real*8 11 , real*10 15 .
IEEE 754 | Java | |||
real*4 | float | 23+ 1 | ||
real*8 | double | 52+ 1 | ||
real*10 | - |
?
( ), m=1 p=1. , 21-d.
, m≈2 p= pmax-1. ,
1 pmax-1
- real*4 2.350989E-38 3.402824E38,
- real*8 2.225074E-308 1.797693E308,
- real*10 3.362103E-4932 1.189731E4932.
|
|
, 0 pmax, , .
0, , 1 ( 0), . . 1. (1- )*21-d. .
2-n, n .
21-d-n.
,
- real*4 1.401298E-45 2.350989E-38,
- real*8 4.940656E-324 2.225074E-308,
- real*10 3.6451995E-4951 3.362103E-4932.
. . IEEE 754 +0 -0. +0 -0 - .
, p=pmax, 1. , Inf (Infinity - ), NaN (Not a Number - ), Ind (Indeterminate ). . , 1 0 Inf, 0 0 Ind. NaN , , ..
Inf . IEEE 754 . 0 + Inf, 1 Inf.
Ind , 0 (, ), 1. NaN. NaN (Signaling NaN) (Quiet NaN). ( ) ( ).
, IEEE 754. , Java , : Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY.
Ind NaN, Float.NaN Double.NaN .
:
s () | p () | m () | |
-NaN ( -) | 11..11 | 11..11 : 10..01 | |
Indeterminate () | 11..11 | 10..00 | |
Signaling -NaN ( -, ) | 11..11 | 01..11 : 00..01 | |
-Infinity ( , ) | 11..11 | 00..00 | |
11..10 : 00..01 | 11..11 : 00..00 | ||
00..00 | 11..11 : 00..01 | ||
-0 | 00..00 | 00..00 | |
+0 | 00..00 | 00..00 | |
00..00 | 00..01 : 11..11 | ||
00..01 : 11..10 | 00..00 : 11..11 | ||
+Infinity ( , ) | 11..11 | 00..00 | |
Signaling +NaN ( -, ) | 11..11 | 00..01 : 01..11 | |
Quiet +NaN ( -) | 11..11 | 10..00 : 11..11 |
|
|
, , int, float, float int. - .
long double:
Float.intBitsToFloat( int)
Double.longBitsToDouble( long)
Float.floatToIntBits( float)
Double.doubleToLongBits( double)
, Float.intBitsToFloat(0x7F7FFFFF) , Float.MAX_VALUE, Float.intBitsToFloat(0x7F800000) Float.POSITIVE_INFINITY,
Float.intBitsToFloat(0xFF800000) Float.NEGATIVE_INFINITY.
Float.intBitsToFloat 0xF800001 0xF800001, Float.NaN.
, , , int float double long. , , , , . (, int double). , , .
4
ü .
ü , , , . , . .
ü AND ( &) 0 , 0, . OR ( |) 1 , 1, .
ü XOR ( ^) , 1 ( , ), . XOR , graphics.setXORMode().
ü ~a.
ü <<, >> >>> , , . m<<n m∙2n, m>>n m 2n.
ü double. , 1.5, -17E2, 0.0. float, f ( float): 1.5f, -17E2f, 0.0f.
ü , . .
ü . , , . , .
:
- , . . .
- .
- , .
|
|
- , , JButton . , . , . . , . , . , .
- , 1+x float f, 1+y double d. x float y double . jLabel1 f-1, jLabel2 d-1. x y, 1E-3 1E-18. .
- * - . , f1(x) f2(x), f1(x)=a(x)-b(x), a(x)=ex, b(x)=1+x, f2(x)= . f2(x) f1(x) , f1(x) f2(x) . f1(x) f2(x) x. float, - double. x . f1_double (x), a_double(x), b_double(x), f1_float(x), a_float(x), b_float(x), f1_float(x)-f2_float(x) f1_double (x) - f2_double (x). x, 1E-8 0.1. .