Hi folks,
Can I invite you to have a quick play with the code below and offer an opinion as to why the second loop always works, and the first one fails as often as it works. Seems to me both should always work. RELEASE, DEBUG and CHECKMATE builds all (mis)behave the same way.
I have occasionally had trouble with computations in logical tests before, if I remember correctly. Looks like a compiler bug to me.
Andy
program descbound
use calculator
integer i
pow = 0
pow1 = 0
pow2 = 0
i = winio@ ('%2.3ob&')
i = winio@ ('Enter an integer power of 10%cb%rd%cb&', pow)
i = winio@ ('(Bogus) next highest power of 10%cb%`rd%cb&', pow1)
i = winio@ ('(Correct) next highest power of 10%cb%`rd%cb&', pow2)
i = winio@ ('%ff%nl%cn%^bt[Calculate]', calculate)
stop
end program descbound
module calculator
double precision, parameter :: ten = 1.0d+1
integer pow, pow1, pow2
double precision deciman, decimax
contains
integer function calculate ()
calculate = 2
deciman = ten** pow
pow1 = 0
do
pow1 = pow1 + 1
if (deciman .lt. ten** dble (pow1)) exit
end do
pow2 = 0
do
pow2 = pow2 + 1
decimax = ten** dble (pow2)
if (deciman .lt. decimax) exit
end do
call window_update@ (pow1)
call window_update@ (pow2)
return
end function calculate
end module calculator