mirror of
https://github.com/nasa/trick.git
synced 2025-01-09 14:32:53 +00:00
14a75508a3
Changed all header file once include variables to follow the same naming convention and not start with any underscores. Also deleted old incorrect copyright notices. Also removed $Id: tags from all files. Fixes #14. Fixes #22.
48 lines
1.0 KiB
C
48 lines
1.0 KiB
C
/*
|
|
PURPOSE:
|
|
(floating point number round off macro.)
|
|
REFERENCE:
|
|
((None))
|
|
ASSUMPTIONS AND LIMITATIONS:
|
|
()
|
|
PROGRAMMERS:
|
|
(((Robert W. Bailey) (LinCom Corp) (4/92) (--) (Realtime)))
|
|
*/
|
|
|
|
#ifndef ROUNDOFF_H
|
|
#define ROUNDOFF_H
|
|
|
|
#define TRICK_ROUNDOFF_MAX 1.e15
|
|
|
|
#define ROUNDOFF(nval,res,val)\
|
|
{\
|
|
double fraction , real , sval , my_remainder ;\
|
|
if( val < (TRICK_ROUNDOFF_MAX*res) ) { \
|
|
real = (double)((long)val) ;\
|
|
fraction = val - real ;\
|
|
sval = fraction / res ;\
|
|
my_remainder = sval - (double)((long)sval) ;\
|
|
if ( val > 0 ) {\
|
|
if( my_remainder <= 0.5 ) {\
|
|
nval = real + (double)((long)sval)*res ;\
|
|
}\
|
|
else {\
|
|
nval = real + (double)((long)sval+1)*res ;\
|
|
}\
|
|
}\
|
|
else {\
|
|
if( my_remainder >= -0.5 ) {\
|
|
nval = real + (double)((long)sval)*res ;\
|
|
}\
|
|
else {\
|
|
nval = real + (double)((long)sval-1)*res ;\
|
|
}\
|
|
}\
|
|
}\
|
|
else { \
|
|
nval = val;\
|
|
}\
|
|
}
|
|
|
|
#endif
|