arrays - Fortran90 comparing real values -
this question has reply here:
why floating point numbers inaccurate? 3 answersi have next subroutine:
subroutine matprod(nkval, matrix, tkval, field) implicit none integer, allocatable, intent(in) :: matrix(:,:,:) real, allocatable, intent(inout) :: tkval(:,:,:) real, allocatable, intent(in) :: nkval(:,:) integer, intent(in) ::field integer :: temp, i, j allocate(tkval(field,size(matrix,dim=1),3)) temp=size(matrix,dim=1) i=1,field j=1,temp tkval(i,j,:)=matmul(matrix(j,:,:),nkval(:,i)) if (tkval(i,j,1).eq.-0.5) tkval(i,j,1)=0.5 endif if (tkval(i,j,2).eq.-0.5) tkval(i,j,2)=0.5 endif if (tkval(i,j,3).eq.-0.5) tkval(i,j,3)=0.5 endif enddo enddo end subroutine matprod where afer matrix multiplication have set of 3d points, know fact contain '-0.5' , want grab , turn them positive 0.5. reason, if statements don't see those. why?
here output sample of "tkval" j counter displayed:
1 0.2500000 0.7499999 0.7499999 2 0.2500000 0.7499999 0.7499999 3 0.7499999 0.2500000 0.7499999 4 0.7499999 0.7499999 0.2500000 5 0.7499999 0.2500000 0.7499999 6 0.7499999 0.7499999 0.2500000 7 -0.5000000 0.0000000 -0.7499999 8 -0.5000000 -0.7499999 0.0000000 9 0.0000000 -0.5000000 -0.7499999 10 0.0000000 -0.7499999 -0.5000000 11 -0.5000000 0.0000000 -0.7499999 12 -0.5000000 -0.7499999 0.0000000 13 0.5000000 0.5000000 -0.2500000 14 0.5000000 -0.2500000 0.5000000 15 0.0000000 -0.5000000 -0.7499999 16 0.0000000 -0.7499999 -0.5000000 17 0.5000000 0.5000000 -0.2500000 18 0.5000000 -0.2500000 0.5000000
so 1 way thought of solve problem:
if ((tkval(i,j,1).lt.-0.49999).and.(tkval(i,j,1).gt.-0.50001)) tkval(i,j,1)=tkval(i,j,1)*(-1) endif if ((tkval(i,j,2).lt.-0.49999).and.(tkval(i,j,2).gt.-0.50001)) tkval(i,j,2)=tkval(i,j,2)*(-1) endif if ((tkval(i,j,3).lt.-0.49999).and.(tkval(i,j,3).gt.-0.50001)) tkval(i,j,3)=tkval(i,j,3)*(-1) arrays if-statement fortran fortran90 real-datatype
No comments:
Post a Comment