< back
#
Ajude o blog a se manter no ar.
Tempo de leitura: 0 min
Paranoia
Today I got paranoid with implicit conversions.
I was sure that iu
would coerce iu * j
to a complex type, divided by a integer would still be of a complex type.
But somehow I was getting a zeroed array in my output, so I got afraid I was having a integer division problem.
! d/dky F(k) = - i * ky * F(k)
do j = -Gy, Gy
iky = iu * j / (2 * Gy + 1)
dF(:,j,:) = - iky * F(:,j,:)
end do
I tried group the multiplication this way I would force the type coercion, right? Still didn’t worked.
! d/dky F(k) = - i * ky * F(k)
do j = -Gy, Gy
iky = (iu * j) / (2 * Gy + 1)
dF(:,j,:) = - iky * F(:,j,:)
end do
So I got paranoid and made a explicit conversion…
iky = iu * real(j,wp) / (2 * Gy + 1)
it didn’t worked either! So I got even MORE paranoid explicit conversions everywhere…
iky = iu * real(j,wp) / real(2 * Gy + 1,wp)
Started checking every other possibility… everything was a lie!
iky = iu * real(j,wp) / (2.0_wp * Gy + 1.0_wp)
Until I finally saw the type of iky:
real(wp) :: ikx, iky, ikz