Representing Numbers On The Computer: What Happened?
Representing Numbers On The Computer: What Happened?
Representing Numbers On The Computer: What Happened?
J N=J!
1 1
2 2
Let’s calculate J! 3 6
4 24
Program Maxnumber 5 120
*
* Check what the max numbers are on the computer 6 720
*
Integer N 7 5040
* 8 40320
N=1
Do J=1,20
9 362880
N=N*J 10 3628800
Print *,J,N
Enddo 11 39916800
*
stop 12 479001600
end
13 1932053504
14 1278945280
What happened? 15 2004310016
16 2004189184
17 -288522240
18 -898433024
19 109641728
20 -2102132736
Winter Semester 2006/7 Computational Physics I Lecture 2 1
Representing Integers
1 + 8 + 23 = 32 bits
(sign) (exponent) (mantissa)
Double precision
1 + 11 + 52 = 64 bits
(sign) (exponent) (mantissa)
x = ( ) iai2 b E
s
s is sign bit
a is normalized so first bit is 1 (radix point - implicit)
E = 1/2 of (maximum exponent -1), or
E=01111111 in single precision
Winter Semester 2006/7 Computational Physics I Lecture 2 5
Representing Real Numbers
If b=00000000
• x=±0.a•2-126
( 2i + 1) 3i
2 3.156181335449 3.156181471570
i=0 3 3.137852907181 3.137852891596
4 3.142604827881 3.142604745663
5 3.141308784485 3.141308785463
6 3.141674280167 3.141674312699
7 3.141568660736 3.141568715942
8 3.141599655151 3.141599773812
9 3.141590356827 3.141590510938
10 3.141593217850 3.141593304503
11 3.141592502594 3.141592454288
12 3.141592741013 3.141592715020
First 16 digits of correct value 13 3.141592741013 3.141592634547
Close to 10-16
Our latest record which was announced already at press release time of 6-th of
December, 2002 was as the followings;
http://www.super-computing.org/pi-hexa_current.html (hexadecimal)
http://www.super-computing.org/pi-decimal_current.html (decimal)
y y x1 x2
+ 1 + 2
y x1 + x2 x1 + x2
First step:
( )
x1 = rd( (1) ( x + x)) (1) ( x) + D (1) x (1 + E1 ) First order in errors
where
x11 x11
x
xn
x1i 1
D (1) =
=
x
j
x1n1
x1n1
x x
1 n
and
1(1)
(1) (1)
E1 =
x1 = x1 x1 D x + ( x)E1
n1
(1)
(1) (2) (r )
y yEr + D x + D x1E1 + + D xr 1Er 1
(r ) (r )
y1 y1
x xn
1
D = D (r ) (1) =
y ym
m
x1 xn
yEr i yi The rounding error on the final answer
yi
D x i
(r ) (1)
x j Propagation of input errors
j x j
The other terms depend on the specific algorithm. The goal is for
the algorithm to not give errors larger than the first two
(unavoidable) errors.
a x1
2
x= x1 = 2 y = x11 x12
b x2
Unavoidable error:
y (a 2 b 2 ) (a 2 b 2 )
y = a b
2 2
x j = + = 2 ( a + b )
j x j a b
y(0) = a 2 b 2 + 2 ( a + b )
a x1
2
x= x1 = 2 y = x11 x12
b x2
Error magnitude estimation:
Procedure II:
1. Calculate a-b and a+b
2. Calculate their product
a x1 x2
x= x1 = y = x11 ix12
b x1 + x2
Error magnitude estimation:
Single precision
2. Calculate (a4-b4) numerically in single and double precision. Compare the resulting
accuracy to the true value for test cases. Compare to the expected precision for
single and double precision calculations.