| 1 |
! Test IEEE_FMA |
| 2 |
! { dg-do run } |
| 3 |
|
| 4 |
use, intrinsic :: ieee_features |
| 5 |
use, intrinsic :: ieee_exceptions |
| 6 |
use, intrinsic :: ieee_arithmetic |
| 7 |
implicit none |
| 8 |
|
| 9 |
integer :: ex |
| 10 |
|
| 11 |
real :: sx1, sx2, sx3 |
| 12 |
double precision :: dx1, dx2, dx3 |
| 13 |
|
| 14 |
! k1 and k2 will be large real kinds, if supported, and single/double |
| 15 |
! otherwise |
| 16 |
integer, parameter :: k1 = & |
| 17 |
max(ieee_selected_real_kind(precision(0.d0) + 1), kind(0.)) |
| 18 |
integer, parameter :: k2 = & |
| 19 |
max(ieee_selected_real_kind(precision(0._k1) + 1), kind(0.d0)) |
| 20 |
|
| 21 |
real(kind=k1) :: lx1, lx2, lx3 |
| 22 |
real(kind=k2) :: wx1, wx2, wx3 |
| 23 |
|
| 24 |
! Float |
| 25 |
|
| 26 |
sx1 = 3 ; sx2 = 2 ; sx3 = 1 |
| 27 |
if (ieee_fma(sx1, sx2, sx3) /= 7) stop 1 |
| 28 |
sx1 = 0 ; sx2 = 2 ; sx3 = 1 |
| 29 |
if (ieee_fma(sx1, sx2, sx3) /= 1) stop 2 |
| 30 |
sx1 = 3 ; sx2 = 2 ; sx3 = 0 |
| 31 |
if (ieee_fma(sx1, sx2, sx3) /= 6) stop 3 |
| 32 |
|
| 33 |
ex = int(log(rrspacing(real(1, kind(sx1)))) / log(real(2, kind(sx1)))) - 1 |
| 34 |
sx1 = 1 + spacing(real(1, kind(sx1))) |
| 35 |
sx2 = 2 ; sx2 = sx2 ** ex ; sx2 = sx2 * 3 |
| 36 |
sx3 = -sx2 |
| 37 |
|
| 38 |
print *, sx1 * sx2 + sx3 |
| 39 |
print *, ieee_fma(sx1, sx2, sx3) |
| 40 |
if (ieee_fma(sx1, sx2, sx3) /= real(3, kind(sx1)) / 2) stop 4 |
| 41 |
|
| 42 |
! Double |
| 43 |
|
| 44 |
dx1 = 3 ; dx2 = 2 ; dx3 = 1 |
| 45 |
if (ieee_fma(dx1, dx2, dx3) /= 7) stop 1 |
| 46 |
dx1 = 0 ; dx2 = 2 ; dx3 = 1 |
| 47 |
if (ieee_fma(dx1, dx2, dx3) /= 1) stop 2 |
| 48 |
dx1 = 3 ; dx2 = 2 ; dx3 = 0 |
| 49 |
if (ieee_fma(dx1, dx2, dx3) /= 6) stop 3 |
| 50 |
|
| 51 |
ex = int(log(rrspacing(real(1, kind(dx1)))) / log(real(2, kind(dx1)))) - 1 |
| 52 |
dx1 = 1 + spacing(real(1, kind(dx1))) |
| 53 |
dx2 = 2 ; dx2 = dx2 ** ex ; dx2 = dx2 * 3 |
| 54 |
dx3 = -dx2 |
| 55 |
|
| 56 |
print *, dx1 * dx2 + dx3 |
| 57 |
print *, ieee_fma(dx1, dx2, dx3) |
| 58 |
if (ieee_fma(dx1, dx2, dx3) /= real(3, kind(dx1)) / 2) stop 4 |
| 59 |
|
| 60 |
! Large kind 1 |
| 61 |
|
| 62 |
lx1 = 3 ; lx2 = 2 ; lx3 = 1 |
| 63 |
if (ieee_fma(lx1, lx2, lx3) /= 7) stop 1 |
| 64 |
lx1 = 0 ; lx2 = 2 ; lx3 = 1 |
| 65 |
if (ieee_fma(lx1, lx2, lx3) /= 1) stop 2 |
| 66 |
lx1 = 3 ; lx2 = 2 ; lx3 = 0 |
| 67 |
if (ieee_fma(lx1, lx2, lx3) /= 6) stop 3 |
| 68 |
|
| 69 |
ex = int(log(rrspacing(real(1, kind(lx1)))) / log(real(2, kind(lx1)))) - 1 |
| 70 |
lx1 = 1 + spacing(real(1, kind(lx1))) |
| 71 |
lx2 = 2 ; lx2 = lx2 ** ex ; lx2 = lx2 * 3 |
| 72 |
lx3 = -lx2 |
| 73 |
|
| 74 |
print *, lx1 * lx2 + lx3 |
| 75 |
print *, ieee_fma(lx1, lx2, lx3) |
| 76 |
if (ieee_fma(lx1, lx2, lx3) /= real(3, kind(lx1)) / 2) stop 4 |
| 77 |
|
| 78 |
! Large kind 2 |
| 79 |
|
| 80 |
wx1 = 3 ; wx2 = 2 ; wx3 = 1 |
| 81 |
if (ieee_fma(wx1, wx2, wx3) /= 7) stop 1 |
| 82 |
wx1 = 0 ; wx2 = 2 ; wx3 = 1 |
| 83 |
if (ieee_fma(wx1, wx2, wx3) /= 1) stop 2 |
| 84 |
wx1 = 3 ; wx2 = 2 ; wx3 = 0 |
| 85 |
if (ieee_fma(wx1, wx2, wx3) /= 6) stop 3 |
| 86 |
|
| 87 |
ex = int(log(rrspacing(real(1, kind(wx1)))) / log(real(2, kind(wx1)))) - 1 |
| 88 |
wx1 = 1 + spacing(real(1, kind(wx1))) |
| 89 |
wx2 = 2 ; wx2 = wx2 ** ex ; wx2 = wx2 * 3 |
| 90 |
wx3 = -wx2 |
| 91 |
|
| 92 |
print *, wx1 * wx2 + wx3 |
| 93 |
print *, ieee_fma(wx1, wx2, wx3) |
| 94 |
if (ieee_fma(wx1, wx2, wx3) /= real(3, kind(wx1)) / 2) stop 4 |
| 95 |
|
| 96 |
end |