[Fortran] 纯文本查看 复制代码 program main
integer,parameter::sp = selected_real_kind(15)
real(kind=sp)::mat_1(3)
real(kind=sp) matrix_A1(2,2)
real(kind=sp) matrix_A(7,7),L(7,7),U(7,7)
integer*4 n,i
!call ieee_set_rounding_mode(ieee_nearest) !设置浮点数的精度
n = 7
mat_1 = (/1.0,2.0,3.0/)
matrix_A1 = reshape((/2.0,2.0,1.0,1.0/),(/2,2/))
matrix_A(:,:) = 0.0d0
matrix_A(1,1:7) = [1.30000000,0.09523810,0.38461538,3.00000000,6.00000000,10.00000000,6.00000000]
!matrix_A(1,1) = 1.30000000_sp !即使定义real*16后矩阵初始化的值也是存在精度丢失
write(*,*)"sp精度位数",sp
!write(*,"(7F13.8)") matrix_A(1,1:7)
write(*,*)"----------输出A矩阵----------"
write(*,"(7F13.8)") (matrix_A(i,:),i=1,7)
pause
end
无论怎么修改selected_real_kind里面要求的精度,但是初始化matrix_A(1,1)得到的值都是1.29999995,而不是预期的1.30000000
单独初始化为matrix_A(1,1) = 1.30000000_sp 输出的值才能是对的
那么如何保证矩阵整个赋值初始化事后 不丢失精度呢
还望大佬们指教
|