On Sep 11, 2:55 pm, nos...@see.signature (Richard Maine) wrote:
I have two pieces of code, one in C and the translated version in
Fortran (see below). I'm translating some vibration code and am
observing small differences at a few point points. Most of the time
the numbers are in complete lockstep - down to the least significant
digit. But in this case I see both routines called with the exact
same arguments BUT the iC vectors (return values) differ:
Fortran iC: (-1.0380980788614978e-06, 1.0380980788614978e-06,
-4.4292627138983793e-35)
C iC: (-1.0380980788614978e-06, 1.0380980788614978e-06, 0.0)
where bC = (-1.0380980788614978d-06, 1.0380980788614978d-06, 0.0)
(gdb) geometry::inert_coord (psi=0, theta=-6.3936888239590959e-13,
phi=6.3936888239590959e-13, bc=..., ic=...) at plates.f95:910
subroutine inert_coord(psi, theta, phi, bC, iC)
double precision, intent(in) :: psi
double precision, intent(in) :: theta
double precision, intent(in) :: phi
double precision, intent(in) :: bC(3)
double precision, intent(out) :: iC(3)
iC(1) = (cos(psi)*cos(theta))*bC(1)
+ &
(-sin(psi)*cos(phi) + cos(psi)*sin(theta)*sin(phi))*bC(2)
+ &
(sin(psi)*sin(phi) + cos(psi)*sin(theta)*cos(phi))*bC(3)
iC(2) = (sin(psi)*cos(theta))*bC(1)
+ &
(cos(psi)*cos(phi) + sin(psi)*sin(theta)*sin(phi))*bC(2)
+ &
(-cos(psi)*sin(phi) + sin(psi)*sin(theta)*cos(phi))*bC(3)
iC(3) = -sin(theta)*bC(1) + cos(theta)*sin(phi)*bC(2) +
cos(theta)*cos(phi)*bC(3)
end subroutine inert_coord
inert_coord (psi=0, theta=-6.3936888239590959e-13,
phi=6.3936888239590959e-13, bC=0xbffd1f98, iC=0xbffd1e48) at
geometry.c:40
void inert_coord(double psi, double theta, double phi, double bC[3],
double iC[3])
{
iC[0] = (cos(psi)*cos(theta))*bC[0] +
(-sin(psi)*cos(phi) + cos(psi)*sin(theta)*sin(phi))*bC[1] +
(sin(psi)*sin(phi) + cos(psi)*sin(theta)*cos(phi))*bC[2];
iC[1] = (sin(psi)*cos(theta))*bC[0] +
(cos(psi)*cos(phi) + sin(psi)*sin(theta)*sin(phi))*bC[1] +
(-cos(psi)*sin(phi) + sin(psi)*sin(theta)*cos(phi))*bC[2];
iC[2] = -sin(theta)*bC[0] + cos(theta)*sin(phi)*bC[1] +
cos(theta)*cos(phi)*bC[2];
}
Why?
---John