[Patch, fortran] PR24518 - Intrinsic MOD incorrect for large arg1/arg2 and slow.
Paul Richard Thomas
paul.richard.thomas@gmail.com
Tue Oct 31 23:24:00 GMT 2006
:ADDPATCH fortran:
This patch concerned the accuracy of results obtained with MOD(arg1,
arg2) and MODULO(arg1, arg2) at large values of the ratio of arg1 to
arg2; these were drifting off and exceeding the absolute value of arg2
for relatively small values of the ratio. For example:
real*8 :: x = 10.0e9
do i = 10, 22
x = 10d0 * x
print '(a,i2,a,g14.8)', "mod (10**",i,", 1.7_8) = ",mod (x, 1.7_8)
end do
end
gives
mod (10**10, 1.7_8) = 1.3000026
mod (10**11, 1.7_8) = 1.1000261
mod (10**12, 1.7_8) = 0.80026150
mod (10**13, 1.7_8) = 1.2026138
mod (10**14, 1.7_8) = 0.12609863
mod (10**15, 1.7_8) = 1.2607422
mod (10**16, 1.7_8) = 5.8125000
mod (10**17, 1.7_8) = -50.687500
mod (10**18, 1.7_8) = 364.00000
mod (10**19, 1.7_8) = -.70000000E+20
mod (10**20, 1.7_8) = -.70000000E+21
mod (10**21, 1.7_8) = -.70000000E+22
mod (10**22, 1.7_8) = -.70000000E+23
with the patch, which calls built_in fmod,
mod (10**10, 1.7_8) = 1.3000026
mod (10**11, 1.7_8) = 1.1000261
mod (10**12, 1.7_8) = 0.80026123
mod (10**13, 1.7_8) = 1.2026123
mod (10**14, 1.7_8) = 0.12612289
mod (10**15, 1.7_8) = 1.2612289
mod (10**16, 1.7_8) = 0.71228947
mod (10**17, 1.7_8) = 0.32289470
mod (10**18, 1.7_8) = 1.5289470
mod (10**19, 1.7_8) = 1.6894697
mod (10**20, 1.7_8) = 1.5946971
mod (10**21, 1.7_8) = 0.64697063
mod (10**22, 1.7_8) = 0.86970625
is returned, which agrees with a leading brand commercial compiler... or two.
The patch is self explanatory, including the calculation of modulo.
This latter is a bit contorted in order to avoid any further
divisions; this is rewarded by the computation time only being 30%
more than that for mod.
We have not included a testcase because anything useful would fail on
platforms without the fmod built_in. If none such exist, we would be
happy to provide a testcase!
Regtested on FC5/x86_ia64 - OK for trunk, and 4.2?
We would like to acknowledge Uros Bizjak for his work in ensuring that
the library can provide the goods for any compiler option. Thanks
Uros!
It so happens that this version of mod and modulo execute pretty quickly too....
FX and Paul
2006-10-31 Francois-Xavier Coudert <fxcoudert@gcc.gnu,org>
Paul Thomas <pault@gcc.gnu.org>
PR fortran/24518
* trans-intrinsic.c (gfc_conv_intrinsic_mod): Use built_in fmod for
both MOD and MODULO, if it is available.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr24518.diff
Type: text/x-patch
Size: 4448 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20061031/9117bcc3/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Change.Logs
Type: application/octet-stream
Size: 229 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20061031/9117bcc3/attachment.obj>
More information about the Fortran
mailing list