Quantcast
Channel: Why do I need 17 significant digits (and not 16) to represent a double? - Stack Overflow
Viewing all articles
Browse latest Browse all 6

Answer by Ondřej Čertík for Why do I need 17 significant digits (and not 16) to represent a double?

$
0
0

The correct answer is the one by Nemo above. Here I am just pasting a simple Fortran program showing an example of the two numbers, that need 17 digits of precision to print, showing, that one does need (es23.16) format to print double precision numbers, if one doesn't want to loose any precision:

program testimplicit noneinteger, parameter :: dp = kind(0.d0)real(dp) :: a, ba = 1.8014398509481982e+16_dpb = 1.8014398509481980e+16_dpprint *, "First we show, that we have two different 'a' and 'b':"print *, "a == b:", a == b, "a-b:", a-bprint *, "using (es22.15)"print "(es22.15)", aprint "(es22.15)", bprint *, "using (es23.16)"print "(es23.16)", aprint "(es23.16)", bend program

it prints:

First we show, that we have two different 'a' and 'b':a == b: F a-b:   2.0000000000000000     using (es22.15)1.801439850948198E+161.801439850948198E+16using (es23.16)1.8014398509481982E+161.8014398509481980E+16

Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>