Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Fortran > Re: whole numbe...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 40 Topic 8533 of 8908
Post > Topic >>

Re: whole number constants

by "robin" <robin_v@[EMAIL PROTECTED] > Jul 22, 2008 at 05:34 AM

"Dick Hendrickson" <dick.hendrickson@[EMAIL PROTECTED]
> wrote in message
news:he7hk.129353$102.58099@[EMAIL PROTECTED]
> dancerchris@[EMAIL PROTECTED]
 wrote:
> > This may be a dumb question but what is "best practice" when coding
> > whole numbers in real (kind specified) formulas.  I am looking for
> > accuracy, consistancy and prortability reagardless of what value dp
> > has below.  Many of my calcs have numerical cancellations or accuracy
> > checks as per the error function below.  What are the pitfalls?
> >
> > for example:
> >
> > integer, parameter :: dp = selected_real_kind(15, 307)
> >
> > real(dp)  :: x,xnew
> >
> > real(dp), parameter :: one = 1.0_dp
> > real(dp), parameter :: onend = 1_dp
> > real(dp), parameter :: onenk = 1.0
> > real(dp), parameter :: onei = 1
> >
>
> For real constants that are exact integers and are small enough
> to fit in one word, those 4 are (almost) exactly equivalent.
> No processor in the world will possibly mess up the conversion
> of 1 or 1.0 or 1.0_dp into some other kind.  My advice would
> be to do what looks natural, as long as you declare the result
> kind, via the "real(dp)".
>
> The interesting exception here is the "1_dp" form.  This
> declares an integer of kind dp.  It's not guaranteed that
> this will be ****table.

It's worse than that.

It isn't correct, and may appear to execute OK
on some systems.
If you are lucky, a particular compiler may issue
an error message because that kind doesn't exist
among the kinds of integers.

>  Many processors only sup****t one kind
> of integer and the selected_real_kind refereence you used
> to get the value of "dp" isn't likely to return a valid
> integer kind.
>
> As you almost certainly know, it's different for values that
> aren't exactly representable.  3.14 and 3.14_dp are not the
> same thing (or at least aren't ****tably the same).
>
> > ! which should I use ?
> >
> > 10 error = one-xnew/x
> > 20 error = onend-xnew/x
> > 30 error = onenk-xnew/x
> > 40 error = onei-xnew/x
> >
> > ! or the more ledgable ?
> >
> > 50 error = 1-xnew/x
> This would be my choice, because it's clearer about
> what you are doing.
>
> The bad thing about getting in the habit of using just
> plain constants is with dummy arguments.  Here, you need
> to specify the kind value as there is no automatic conversion.
>
> Dick Hendrickson
> >
> > ! or the slightly less ledgable ?
> >
> > 60 error = 1_dp-xnew/x
> >
> > Thanks for any advice.
 




 40 Posts in Topic:
whole number constants
dancerchris@[EMAIL PROTEC  2008-07-21 14:16:11 
Re: whole number constants
Craig Powers <craig.po  2008-07-21 17:20:00 
Re: whole number constants
dancerchris@[EMAIL PROTEC  2008-07-21 14:27:13 
Re: whole number constants
nospam@[EMAIL PROTECTED]   2008-07-21 15:00:02 
Re: whole number constants
Dick Hendrickson <dick  2008-07-21 21:30:53 
Re: whole number constants
"robin" <rob  2008-07-22 05:34:44 
Re: whole number constants
Dick Hendrickson <dick  2008-07-22 15:02:50 
Re: whole number constants
"robin" <rob  2008-07-23 05:14:08 
Re: whole number constants
Dick Hendrickson <dick  2008-07-23 15:26:15 
Re: whole number constants
dancerchris@[EMAIL PROTEC  2008-07-21 14:49:41 
Re: whole number constants
glen herrmannsfeldt <g  2008-07-21 15:33:55 
Re: whole number constants
dancerchris@[EMAIL PROTEC  2008-07-21 14:52:15 
Re: whole number constants
nospam@[EMAIL PROTECTED]   2008-07-21 15:27:09 
Re: whole number constants
"robin" <rob  2008-07-22 05:34:36 
Re: whole number constants
dancerchris@[EMAIL PROTEC  2008-07-21 15:51:23 
Re: whole number constants
nospam@[EMAIL PROTECTED]   2008-07-21 16:38:16 
Re: whole number constants
Paul van Delst <Paul.v  2008-07-22 09:24:25 
Re: whole number constants
glen herrmannsfeldt <g  2008-07-22 09:11:17 
Re: whole number constants
"robin" <rob  2008-07-23 05:14:05 
Re: whole number constants
"J. F. Cornwall"  2008-07-23 19:15:05 
Re: whole number constants
glen herrmannsfeldt <g  2008-07-21 16:52:25 
Re: whole number constants
nospam@[EMAIL PROTECTED]   2008-07-21 17:41:43 
Re: whole number constants
dancerchris@[EMAIL PROTEC  2008-07-21 15:58:09 
Re: whole number constants
Paul van Delst <Paul.v  2008-07-22 09:14:32 
Re: whole number constants
dancerchris@[EMAIL PROTEC  2008-07-21 17:49:19 
Re: whole number constants
"robin" <rob  2008-07-22 05:34:37 
Re: whole number constants
nospam@[EMAIL PROTECTED]   2008-07-22 01:35:01 
Re: whole number constants
glen herrmannsfeldt <g  2008-07-22 09:19:55 
Re: whole number constants
"robin" <rob  2008-07-23 05:14:06 
Re: whole number constants
glen herrmannsfeldt <g  2008-07-22 23:39:36 
Re: whole number constants
"robin" <rob  2008-10-02 14:56:53 
Re: whole number constants
"robin" <rob  2008-10-02 14:56:52 
Re: whole number constants
glen herrmannsfeldt <g  2008-10-02 13:44:10 
Re: whole number constants
glen herrmannsfeldt <g  2008-07-24 22:06:52 
Re: whole number constants
Thomas Koenig <tkoenig  2008-07-22 08:04:03 
Re: whole number constants
lindahl@[EMAIL PROTECTED]  2008-07-22 03:07:29 
Re: whole number constants
"Les" <l.nei  2008-07-22 11:34:53 
Re: whole number constants
glen herrmannsfeldt <g  2008-07-22 09:24:39 
Re: whole number constants
Thomas Koenig <tkoenig  2008-07-24 06:17:59 
Re: whole number constants
Michael Prager <Mike.P  2008-07-24 10:21:33 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Nov 19 8:48:55 CST 2008.