111
|
1 ! { dg-do run }
|
|
2 ! PR fortran/49010
|
|
3 ! MOD/MODULO sign of zero.
|
|
4
|
|
5 ! We wish to provide the following guarantees:
|
|
6
|
|
7 ! MOD(A, P): The result has the sign of A and a magnitude less than
|
|
8 ! that of P.
|
|
9
|
|
10 ! MODULO(A, P): The result has the sign of P and a magnitude less than
|
|
11 ! that of P.
|
|
12
|
|
13 ! Here we test only with constant arguments (evaluated with
|
|
14 ! mpfr_fmod), as we don't want to cause failures on targets with a
|
|
15 ! crappy libm. But, a target where fmod follows C99 Annex F is
|
|
16 ! fine. Also, targets where GCC inline expands fmod (such as x86(-64))
|
|
17 ! are also fine.
|
|
18 program mod_sign0_1
|
|
19 implicit none
|
|
20 real :: r, t
|
|
21
|
|
22 r = mod (4., 2.)
|
|
23 t = sign (1., r)
|
131
|
24 if (t < 0.) STOP 1
|
111
|
25
|
|
26 r = modulo (4., 2.)
|
|
27 t = sign (1., r)
|
131
|
28 if (t < 0.) STOP 2
|
111
|
29
|
|
30 r = mod (-4., 2.)
|
|
31 t = sign (1., r)
|
131
|
32 if (t > 0.) STOP 3
|
111
|
33
|
|
34 r = modulo (-4., 2.)
|
|
35 t = sign (1., r)
|
131
|
36 if (t < 0.) STOP 4
|
111
|
37
|
|
38 r = mod (4., -2.)
|
|
39 t = sign (1., r)
|
131
|
40 if (t < 0.) STOP 5
|
111
|
41
|
|
42 r = modulo (4., -2.)
|
|
43 t = sign (1., r)
|
131
|
44 if (t > 0.) STOP 6
|
111
|
45
|
|
46 r = mod (-4., -2.)
|
|
47 t = sign (1., r)
|
131
|
48 if (t > 0.) STOP 7
|
111
|
49
|
|
50 r = modulo (-4., -2.)
|
|
51 t = sign (1., r)
|
131
|
52 if (t > 0.) STOP 8
|
111
|
53
|
|
54 end program mod_sign0_1
|