Re: Rounding off double precision
- From: Louis Krupp <lkrupp@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 30 Mar 2008 22:12:47 -0600
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"(snip)
has type double precision, in Fortran, the literal constant "0.1" has
type single precision. So
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
.
- Follow-Ups:
- Re: Rounding off double precision
- From: Louis Krupp
- Re: Rounding off double precision
- From: glen herrmannsfeldt
- Re: Rounding off double precision
- References:
- Rounding off double precision
- From: Bamm
- Re: Rounding off double precision
- From: Bamm
- Re: Rounding off double precision
- From: Richard Maine
- Re: Rounding off double precision
- From: Bamm
- Re: Rounding off double precision
- From: e p chandler
- Re: Rounding off double precision
- From: Bamm
- Re: Rounding off double precision
- From: glen herrmannsfeldt
- Re: Rounding off double precision
- From: Charles Coldwell
- Re: Rounding off double precision
- From: glen herrmannsfeldt
- Rounding off double precision
- Prev by Date: Re: data with metadata
- Next by Date: Re: How to read files with commas as separators?
- Previous by thread: Re: Rounding off double precision
- Next by thread: Re: Rounding off double precision
- Index(es):
Relevant Pages
|