forked from NOAA-GFDL/FMS
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
While looking at the source code as part of #6 , I see that the readability for these lines could be improved significantly. Existing code:
#ifdef NO_QUAD_PRECISION
double px, py, pz, qx, qy, qz, ddd;
#ifndef SQRT_
#define SQRT_ sqrt
#else
#error "SQRT_ Previously Defined"
#endif /* SQRT_ */
#ifndef ABS_
#define ABS_ fabsl
#else
#error "ABS_ Previously Defined"
#endif /* ABS_ */
#else
long double px, py, pz, qx, qy, qz, ddd;
#ifndef SQRT_
#define SQRT_ sqrtl
#else
#error "SQRT_ Previously Defined"
#endif /* SQRT_ */
#ifndef ABS_
#define ABS_ fabs
#else
#error "ABS_ Previously Defined"
#endif /* ABS_ */
#endifMy suggestion would be to re-write as - which makes the code concise, performs error-checking first (instead of inter-mixing with actual code) and make the code more readable (while also fixing #6):
#if defined(SQRT_) || defined(ABS_)
#error SQRT_ or ABS_ should not be defined
#endif
#ifdef NO_QUAD_PRECISION
#define VARTYPE_ double
#define SQRT_ sqrt
#define ABS_ fabs
#else
#define VARTYPE_ long double
#define SQRT_ sqrtl
#define ABS_ fabsl
#endif
VARTYPE_ px, py, pz, qx, qy, qz, ddd;Might also be worthwhile to add an #undef VARTYPE_ at the end of the function
Related: I see that the arccos is always set to acosl here rather than acosl or acos depending on the value of NO_QUAD_PRECISION. Perhaps that is intentional - @chrisb13?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels