At 09:35 PM 7/14/2002, Aaron Bannert wrote:
On Sun, Jul 14, 2002 at 07:27:04PM -0700, Brian Pane wrote:
How exactly is the subtraction slower?I'm not at all sure what you
mean by people matching on the struct directly...
For addition...
rtm.sec = tm1.sec + tm2.sec;
rtm.usec = tm1.usec + tm2.usec;
if (rtm.usec >= 1000000 && rtm.sec > 0) {
rtm.usec -= 1000000
++rtm.sec;
}
else if (rtm.usec <= -1000000 && rtm.sec < 0) {
rtm.usec += 1000000
--rtm.sec;
}
else if (rtm.usec >= 0 && rtm.sec < 0) {
rtm.usec -= 1000000
++rtm.sec;
}
else if (rtm.usec <= 0 && rtm.sec > 0) {
rtm.usec += 1000000
--rtm.sec;
}
For subtraction...
rtm.sec = tm1.sec + tm2.sec;
rtm.usec = tm1.usec + tm2.usec;
[ditto above conditionals]
Approximately, presuming that usec is always expressed in the
same sign as sec and signed values are allowed. Remember that
addition may be n + -n, and contra wise for subtraction, so all the
same conditions apply
Bill