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 24 of 40 Topic 8533 of 8908
Post > Topic >>

Re: whole number constants

by Paul van Delst <Paul.vanDelst@[EMAIL PROTECTED] > Jul 22, 2008 at 09:14 AM

dancerchris@[EMAIL PROTECTED]
 wrote:
> p.s.
> 
> I know for the stuff that I am doing that label 100 is safe practice
> and works well.
> 
> I was trying to be a little more compact/ledgable with the coding with
> preferably something like label 300.  The problems I have run into are
> generally with error functions and comparison of like values between
> subroutines/functions, but I think it is perhaps overly conservative
> to specify a parameter for a whole number rather than use coding like
> label 300

The fact that you're confused about what is and isn't the same suggests
you should stick 
to what you know is "correct" (still trying to understan the differences
though, of course 
:o). You should code defensively and think about the people that will come
after you, not 
just how pretty you want the code to look. If you are confused as to
whether

   100 error = one-xnew/x+one
   200 error = 1.0_dp-xnew/x+1.0_dp
   300 error = 1-xnew/x+1

are consistent, chances are so will future maintainers of the code. You
taking five 
minutes to be crystal clear about what you're doing will save them a lot
more time if the 
same question occurs to them.

I prefer the form

   real(dp), parameter :: one = 1.0_dp
   ....
   100 error = one-xnew/x+one

because it is pretty much completely unambiguous. So is the second one
(200) if you don't 
mind typing the kind type suffix all over (it may not always be nice and
short like "dp"). 
The third one (300) is o.k. if you're always going to stick to whole
numbers like 1. But 
if you get into the habit, you could end up doing something like,

   integer, parameter :: dp = selected_real_kind(15)
   real(dp) :: var, x, y
   ....
   var = 0.1 + x/(y - 0.15)

where now the literal constants are not represented to the same precision
as the variables 
are typed because you've specified them only to single precision.

If you're in the business of writing tangent-linear and adjoint forms of
models, these 
little precision hiccups can add up.

cheers,

paulv
 




 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 9:38:28 CST 2008.