Re: increasing width
- From: "robin" <robin_v@xxxxxxxxxxx>
- Date: Sat, 24 Mar 2007 23:03:07 GMT
"Gordon Sande" <g.sande@xxxxxxxxxxxxxxxx> wrote in message
news:2007031116234516807-gsande@xxxxxxxxxxxxxxxxx
On 2007-03-11 14:43:37 -0300, Dick Hendrickson <dick.hendrickson@xxxxxxx>said:
Brooks Moses wrote:
Lane Straatman wrote:
After reading Dick's post, I went back and wrote:
total = 0.0_dp
That's harmless, but it really doesn't do anything. If you write
total = 0
or
total = 0.0
the compiler will (and must) do an automatic conversion of either
zero to double precision. The problem is that zero is correctly
represented in any precision on any existing machine. It's numbers
like .1 that need to be "cast". Using Brooks' example of the REAL
function isn't what you want (sorry Brooks ;( ) for the general case.
If you try something like REAL( .1, dp) you won't get what you
expect. The ".1" is still a single precision value and is converted
to double by appending 32 zero bits. That doesn't improve the
approximation. To get full precision double precision constants
you need to append the kind selector to the constant and write
".1_dp". It's kind of clunky and verbose, but it's the only
guaranteed way to do it.
Dick Hendrickson
In the example at hand, namely one tenth, it is possible to use
real ( 1.0, dp ) / real ( 10.0, dp )
which relies on the fact that ten is exactly represented in many
systems and let the divide provide all the accurracy.
That's exactly the same as .1_dp,
and .1_dp is clearer and simpler to write.
.
- References:
- increasing width
- From: Lane Straatman
- Re: increasing width
- From: Steve Lionel
- Re: increasing width
- From: Lane Straatman
- Re: increasing width
- From: Steve Lionel
- Re: increasing width
- From: Lane Straatman
- Re: increasing width
- From: Brooks Moses
- Re: increasing width
- From: Dick Hendrickson
- Re: increasing width
- From: Gordon Sande
- increasing width
- Prev by Date: Re: Newbie Question!
- Next by Date: Re: increasing width
- Previous by thread: Re: increasing width
- Next by thread: Re: increasing width
- Index(es):
Relevant Pages
|