trick/trick_source/sim_services/include/roundoff.h
Alex Lin 14a75508a3 Cleaning up once include variables and copyright cleanup.
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.
2015-03-23 16:03:14 -05:00

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