The following code: 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 gives, on x86_64-pc-mingw32, the output: 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 while it should give something like (here on i686-apple-darwin): 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 (reported by James Van Buskirk in comp.lang.fortran: http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/e9add97708681397) -- Summary: [win64] Wrong results for RRSPACING, SCALE, SET_EXPONENT and SPACING Product: gcc Version: 4.4.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: fxcoudert at gcc dot gnu dot org GCC build triplet: x86_64-pc-mingw32 GCC host triplet: x86_64-pc-mingw32 GCC target triplet: x86_64-pc-mingw32 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36063