Re: Rounding off double precision



glen herrmannsfeldt wrote:
Charles Coldwell wrote:
(snip, I wrote)
C uses #define is places where Fortran uses PARAMETER,
but #define is typeless.

There's a little more to it than that. In C, the literal constant "0.1"
has type double precision, in Fortran, the literal constant "0.1" has
type single precision. So
(snip)

Actually, now that I look at it, the OP actually had the opposite
problem, analogous to

X = 0.1D0

where X is implicitly typed default real (single precision), but the
literal constant has type double precision.

Well, the OP had:

double precision Speed, Azimuth, V
Azimuth = 90.
parameter(Pi = 3.141592653589793238d0)
V = Speed * cos(Azimuth * Pi / 180.)

A double precision constant as a single precision PARAMETER
used in a double precision expression. The C equivalent

#define PI 3.141592653589793238

as you say, the constant is double precision (without an f),
but PI itself is typeless. You can do things like:

#define ABS(x,y) ((x)>(y)?(x):(y))

as a typeless absolute value in C89. (It wont' work for complex
types in C99.)

I think you mean MIN instead of ABS. ABS would be something like:

#define ABS(x) ((x) >= 0 ? (x) : -(x))

Unlike a FORTRAN statement function, which this vaguely resembles, macros that use an argument in more than one place do weird things when passed an expression with side effects, e.g., ABS(x++).

Louis
.



Relevant Pages

  • Re: Rounding off double precision
    ... has type double precision, in Fortran, the literal constant "0.1" has ... A double precision constant as a single precision PARAMETER ... but PI itself is typeless. ...
    (comp.lang.fortran)
  • Re: Rounding off double precision
    ... "3.141592653589793238d0" and is a double precision value. ... A parameter is not a literal constant and vice-versa. ... literal constant to a single precision named parameter: ... you can assign a single precision literal constant to a double ...
    (comp.lang.fortran)
  • Re: Rounding off double precision
    ... A parameter is a symbolic constant, not a literal constant. ... support quad precision, there is no statement that will work. ... will work on any processor that uses increasing kind values for ...
    (comp.lang.fortran)
  • Re: Rounding off double precision
    ... has type double precision, in Fortran, the literal constant "0.1" has ... A double precision constant as a single precision PARAMETER ... but PI itself is typeless. ...
    (comp.lang.fortran)
  • Re: Rounding off double precision
    ... because I didn't declare Pi to be double precision, ... C uses #define is places where Fortran uses PARAMETER, ... has type double precision, in Fortran, the literal constant "0.1" has ... type single precision. ...
    (comp.lang.fortran)