主题:[讨论]【基本功训练 03】浮点数转换 精度丢失
IVF11.1 帮助文档上有如下一段话:
When a single-precision real operand is converted to a double-precision real operand, low-order binary digits are set to zero. This conversion does not increase accuracy; conversion of a decimal number does not produce a succession of decimal zeros. For example, a REAL variable having the value 0.3333333 is converted to approximately 0.3333333134651184D0. It is not converted to either 0.3333333000000000D0 or 0.3333333333333333D0.
其实,当我们熟悉浮点数表示后,0.3333333134651184D0 这个数是可以算出来的。这类似于一个课后练习题,可以帮助我们很好地理解浮点数的相关知识。
另外,我们还可以算一个很简单的实数,比如 0.1,赋给双精度后,
program main
implicit none
character(len = 20):: fmt_str
double precision:: dx
fmt_str = "(D24.16)"
dx = 0.1
write(unit = *, fmt = fmt_str) dx
stop
end program
您能直接写出结果吗?(不上机实验)
When a single-precision real operand is converted to a double-precision real operand, low-order binary digits are set to zero. This conversion does not increase accuracy; conversion of a decimal number does not produce a succession of decimal zeros. For example, a REAL variable having the value 0.3333333 is converted to approximately 0.3333333134651184D0. It is not converted to either 0.3333333000000000D0 or 0.3333333333333333D0.
其实,当我们熟悉浮点数表示后,0.3333333134651184D0 这个数是可以算出来的。这类似于一个课后练习题,可以帮助我们很好地理解浮点数的相关知识。
另外,我们还可以算一个很简单的实数,比如 0.1,赋给双精度后,
program main
implicit none
character(len = 20):: fmt_str
double precision:: dx
fmt_str = "(D24.16)"
dx = 0.1
write(unit = *, fmt = fmt_str) dx
stop
end program
您能直接写出结果吗?(不上机实验)