Re: increasing width



"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)


.



Relevant Pages

  • RE: Undocumented alternate form for %#f ?
    ... conversions, the first character of the output string is made ... zero. ... No difference with the alternate specification here as the precision is ... This gives the minimum number of digits to appear for d, i, o, ...
    (comp.lang.python)
  • Re: Field changed from Single to Double issue..
    ... >by hand as 0.3 so there is no precision issue with it. ... >>I think you're missing two zeros in the precision ... >conversions work. ... >>You could maybe do your conversions via a Recordset. ...
    (microsoft.public.access.conversion)
  • Re: Field changed from Single to Double issue..
    ... >I think you're missing two zeros in the precision there... ... >You could maybe do your conversions via a Recordset. ... truncation to control ...
    (microsoft.public.access.conversion)
  • Re: Undocumented alternate form for %#f ?
    ... conversions, the first character of the output string is made ... zero. ... No difference with the alternate specification here as the precision is ... This gives the minimum number of digits to appear for d, i, o, ...
    (comp.lang.python)
  • Re: (decimal) 1.1 versus 1.1M
    ... so conversions between the two may lose information. ... Double, however, has less precision overall than decimal. ... so it runs out of digits of precision much more ... double value to a decimal format and stores it in de. ...
    (microsoft.public.dotnet.languages.csharp)