I'm in the process of putting some example programs
togethor to help explain some of the problems
that occur because of representing numeric data
in a binary format.
I've written a simple program that illustrates
some of this and it is given below. I've also
included sample output from nagace f90
on a sun box.
my first question concerns edit descriptors.
Does output always involved rounding? Is this
rounding implementation dependent?
I was taught about different number bases when I was at
secondary school (11-18) but I find that few of the
students I teach today have been taught much in this area.
Does anyone know of source code (preferably where you can
specify the number base of both the input data and the
output data), or a reference to any texts that might address
this issue?
thanks in advance
----------------------
Ian Chivers
[log in to unmask]
Fortran Source - sorry if the equivalence upsets anyone :-)
program test
real :: x1=1.0
real :: x2=0.1
real :: x3=0.01
real :: x4=0.001
real :: x5=0.0001
integer :: j,i1,i2,i3,i4,i5
character (len=32) :: cx1,cx2,cx3,cx4,cx5
equivalence (i1,x1)
equivalence (i2,x2)
equivalence (i3,x3)
equivalence (i4,x4)
equivalence (i5,x5)
write(unit=*,fmt=10) x1
write(unit=*,fmt=10) x2
write(unit=*,fmt=10) x3
write(unit=*,fmt=10) x4
write(unit=*,fmt=10) x5
10 format(1x,g15.8)
do j=0,31
if (btest(i1,j)) then
cx1(32-j:32-j)='1'
else
cx1(32-j:32-j)='0'
endif
enddo
do j=0,31
if (btest(i2,j)) then
cx2(32-j:32-j)='1'
else
cx2(32-j:32-j)='0'
endif
enddo
do j=0,31
if (btest(i3,j)) then
cx3(32-j:32-j)='1'
else
cx3(32-j:32-j)='0'
endif
enddo
do j=0,31
if (btest(i4,j)) then
cx4(32-j:32-j)='1'
else
cx4(32-j:32-j)='0'
endif
enddo
do j=0,31
if (btest(i5,j)) then
cx5(32-j:32-j)='1'
else
cx5(32-j:32-j)='0'
endif
enddo
print *,'1234567890123456789012345678901234567890'
print *,cx1
print *,cx2
print *,cx3
print *,cx4
print *,cx5
end program test
===========================
Sample output
1.0000000
0.1000000
9.9999998E-03
1.0000000E-03
9.9999997E-05
1234567890123456789012345678901234567890
00111111100000000000000000000000
00111101110011001100110011001101
00111100001000111101011100001010
00111010100000110001001001101111
00111000110100011011011100010111
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|