Re: increasing width



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


.



Relevant Pages

  • Re: Universe PRECISION vs everyone else...
    ... And you can avoid the whole precision problem by doing all calculations ... Back in our early UniVerse days, some of our users in NT4 ... struck the zero not equal to zero problem and we were advised to ... decided to run all our Universe programs with no decimals at all...hope ...
    (comp.databases.pick)
  • Re: Calendrical centering
    ... Detonation of the first A-bomb July 16, ... That's a reason I like the end of the Younger Dryas as a zero point. ... Digital watches would need to carry 18 digits, ... Moreover, the setting of today's current time lacks a bit of precision, ...
    (talk.origins)
  • Re: Dumbfounding Loop Result
    ... can fail with floating ... usually very small for double precision. ... zero), but it is usually good enough for stochastic data. ...
    (comp.soft-sys.matlab)
  • Re: How to increase Working Precision?
    ... I don't get credit for letting "generally outstanding" slip by? ... and 9.95, with three correct digits. ... It printed as zero because it ... is deemed to have too little precision to print otherwise ...
    (sci.math.symbolic)
  • Re: Calendrical centering
    ... Detonation of the first A-bomb July 16, ... That's a reason I like the end of the Younger Dryas as a zero point. ... Digital watches would need to carry 18 digits, ... Moreover, the setting of today's current time lacks a bit of precision, ...
    (talk.origins)