Re: increasing width
- From: "robin" <robin_v@xxxxxxxxxxx>
- Date: Sat, 24 Mar 2007 23:03:09 GMT
"Steve Lionel" <steve.lionel@xxxxxxxxx> wrote in message
news:1173571306.956459.181810@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Mar 10, 6:36 pm, "Lane Straatman" <inva...@xxxxxxxxxxx> wrote:
It seems I have single precision. What gives?
This expression:
((-1)**i)*((x/2.0)**(2*i+p))
is single precision. It does not get converted to double precision
until the assignment to term, but all that does is append zero
fraction bits. Try this instead, which I have enhanced for clarity
using a contained procedure and eliminated implicit type conversions
where it made sense to do so.
program numsci1
IMPLICIT NONE
integer, parameter :: DP = SELECTED_REAL_KIND(13,37)
integer :: iterations, i, p, x
real(KIND=DP) :: total, term
iterations = 20
total = 0
x = 7
p = 5
do i = 0, iterations - 1 ! i is maxed at iterations
term = ((-1_DP)**i)*((x/2.0_DP)**(2*i+p))
No, -1_DP does not give double precision.
In any case, (-1)**i is sufficient here, as its value is either 1 or -1.
(on some compilers, the -1_DP gives 16-bit integers)
.
- References:
- increasing width
- From: Lane Straatman
- Re: increasing width
- From: Steve Lionel
- Re: increasing width
- From: Lane Straatman
- Re: increasing width
- From: Steve Lionel
- increasing width
- Prev by Date: Re: increasing width
- Next by Date: Re: Why float is called as 'float', not 'real'?
- Previous by thread: Re: increasing width
- Next by thread: Re: increasing width
- Index(es):
Relevant Pages
|