> and then lots of calculations showing not very many correct figures.
> With only 7 significant figures quoted in E0 you can't hope for better
> in anything depending on it, and atan(1.0) is the single-precision
> version of atan. So I'd leave c as is, but change the statements
> evaluating PIE, U0 and E0 to
>
> PIE = 4.0_dp*atan(1.0_dp)
> U0 = 4e-7_dp * PIE
> E0 = 1/ (U0*c**2) ! because **2 is better for integer powers
Does an integer exponent make for a mixed-mode calculation?
>>One question: If I have a variable declared as dp and assign it a
>>value like (1E-7)*4.0 , am I well-advised to append _dp on the things
>>on the RHS?
>
> Yes. Two reasons.
> 1. You sometimes lose accuracy if you don't, so it's safer to get
> into the habit of avoiding single-precision real (or complex) numbers
> in double-precision expressions.
> 2. If you think that single precision might be enough or that quadruple
> precision is needed (and available), you have to change only one
> statement in the entire program: the definition of dp. That's also a
> reason to avoid writing PIE = 4d0*atan(1d0) even though it's briefer.
program elliot8
implicit none
integer, parameter :: dp = kind(1.0d0)
real(kind=dp):: U0,E0,PIE, c, e0_calc
PIE = 4.0_dp* atan(1.0_dp)
U0=(1E-7_dp)*4.0_dp * PIE
E0= 8.854187E-12_dp
c = 2.99792458E8_dp
e0_calc = 1.0_dp/ (U0 * c**2.0_dp)
write (*,'(f35.25)') c, U0, PIE,E0, e0_calc
write (*,*) "12345678.0000000000012345678911234"
write (*,*) "12345678.1234567891123456789212345"
end program elliot8
!end source begin output
299792458.0000000000000000000000000
0.0000012566370614359172885
3.1415926535897931160000000
0.0000000000088541870000000
0.0000000000088541878176204
12345678.0000000000012345678911234
12345678.1234567891123456789212345
I think this version gives as much width on epsilon nought as double
precision can do. I can't believe I got stung with a single-precision
pi. It may have been an over-reaction, but I went through and
appended _dp to every constant. It isn't my idea of pretty, but
wouldn't making everything dp be the best way to avoid having
something implicitly single precision? In particular, it looks odd as
an exponent.
--
Wade Ward