Re: Are f.p. manipulation functions only used in initialization?




"James Van Buskirk" <not_valid@xxxxxxxxxxx> wrote in message
news:6_6dnatLa7meCY7VnZ2dnUVZ_qiinZ2d@xxxxxxxxxxxxxx
I was writing some code with gfortran and found that spacing only
worked in initialization expressions. Doesn't anyone else use the
floating point manipulation functions in ordinary expressions and
specification expressions? Testing with gfortran I found that
RRSPACING, SCALE, SET_EXPONENT, and, SPACING were broken like this,
while EXPONENT, FRACTION, and NEAREST seemed to work:


C:\gfortran\james\archpi>c:\gfortran\win64\bin\x86_64-pc-mingw32-gfortran -v
Using built-in specs.
Target: x86_64-pc-mingw32
Configured with:
../../trunk/configure --prefix=/home/FX/irun64 --build=i586-pc-

mingw32 --target=x86_64-pc-mingw32 --with-gmp=/home/FX/local --enable-langua
ges=
c,fortran --disable-werror --disable-nls --enable-threads
Thread model: win32
gcc version 4.4.0 20080421 (experimental) [trunk revision 134506] (GCC)

C:\gfortran\james\archpi>type spacing_bug.f90
program spacing_bug
implicit none
real, parameter :: x1 = 3.14159265358979
integer, parameter :: ulps1 = 2
real, parameter :: y1 = ulps1*spacing(x1) ! Only f03
real, parameter :: y2 = rrspacing(x1) ! Only f03
real, parameter :: y3 = scale(x1,ulps1) ! Only f03
real, parameter :: y4 = set_exponent(x1,ulps1) ! Only f03
real x
integer ulps

write(*,*) 'ulps1*spacing(x1) = ', y1
write(*,*) 'rrspacing(x1) = ', y2
write(*,*) 'scale(x1,ulps1) = ', y3
write(*,*) 'set_exponent(x1,ulps1) = ', y4
x = x1
ulps = ulps1
call sub(x,ulps)
end program spacing_bug

subroutine sub(x,ulps)
implicit none
real x
integer ulps
integer j1(int(ulps*spacing(x)))
integer j2(int(rrspacing(x))/100000)
integer j3(int(scale(x,ulps)))
integer j4(int(set_exponent(x,ulps)))

write(*,*) 'ulps*spacing(x) = ', ulps*spacing(x)
write(*,*) 'rrspacing(x) = ', rrspacing(x)
write(*,*) 'scale(x,ulps) = ', scale(x,ulps)
write(*,*) 'set_exponent(x,ulps) = ', set_exponent(x,ulps)
write(*,*) 'size(j1) = ', size(j1)
write(*,*) 'size(j2) = ', size(j2)
write(*,*) 'size(j3) = ', size(j3)
write(*,*) 'size(j4) = ', size(j4)
end subroutine sub

C:\gfortran\james\archpi>c:\gfortran\win64\bin\x86_64-pc-mingw32-gfortran
spacin
g_bug.f90 -ospacing_bug

C:\gfortran\james\archpi>spacing_bug
ulps1*spacing(x1) = 4.76837158E-07
rrspacing(x1) = 13176795.
scale(x1,ulps1) = 12.566371
set_exponent(x1,ulps1) = 3.1415927
ulps*spacing(x) = 2.0000000
rrspacing(x) = 3.1415927
scale(x,ulps) = 3.1415927
set_exponent(x,ulps) = 0.78539819
size(j1) = 2
size(j2) = 0
size(j3) = 3
size(j4) = 0

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


On Windows, my result (4.4.0 20080425) is as:

C:\TEMP\fortran>a
ulps1*spacing(x1) = 4.76837158E-07
rrspacing(x1) = 13176795.
scale(x1,ulps1) = 12.566371
set_exponent(x1,ulps1) = 3.1415927
ulps*spacing(x) = 4.76837158E-07
rrspacing(x) = 13176795.
scale(x,ulps) = 12.566371
set_exponent(x,ulps) = 3.1415927
size(j1) = 0
size(j2) = 131
size(j3) = 12
size(j4) = 3





.



Relevant Pages