Skip to content
Snippets Groups Projects
Commit f3844207 authored by Thomas Jahns's avatar Thomas Jahns :cartwheel:
Browse files

Replace looping with direct computation.

parent 77192531
No related branches found
No related tags found
1 merge request!5Intentional change
......@@ -1760,41 +1760,26 @@ elementwiseScalarMultiplyTimeDelta(struct _timedelta* base_td, int64_t lambda, s
scaled_td->sign = '+';
/* Sign already handled above. Make lambda positive. */
if (lambda < 0)
lambda *= -1;
lambda = (int64_t)(llabs(lambda));
/* Multiply each element by scalar. */
int64_t ms_temp = lambda * base_td->ms;
scaled_td->ms = (int)(ms_temp % NO_OF_MS_IN_A_SECOND);
int64_t s_temp = lambda*base_td->second + ms_temp / NO_OF_MS_IN_A_SECOND;
scaled_td->second = (int)(s_temp % 60);
scaled_td->ms += (int) lambda*base_td->ms;
while ( scaled_td->ms >= NO_OF_MS_IN_A_SECOND )
{
scaled_td->ms -= NO_OF_MS_IN_A_SECOND;
scaled_td->second += 1;
}
scaled_td->second += (int) lambda*base_td->second;
while ( scaled_td->second >= 60 )
{
scaled_td->second -= 60;
scaled_td->minute += 1;
}
scaled_td->minute += (int) lambda*base_td->minute;
while ( scaled_td->minute >= 60 )
{
scaled_td->minute -= 60;
scaled_td->hour += 1;
}
int64_t m_temp = lambda*base_td->minute + s_temp / 60;
scaled_td->minute = (int)(m_temp % 60);
scaled_td->hour += (int) lambda*base_td->hour;
int64_t h_temp = lambda*base_td->hour + m_temp / 60;
scaled_td->hour = (int)(h_temp % NO_OF_HOURS_IN_A_DAY);
/* Scalar multiplication can not give a value in excess of 24 hours. */
if ( scaled_td->hour >= NO_OF_HOURS_IN_A_DAY )
{
/* ERROR: Return on NULL. */
return NULL;
}
/* Scalar multiplication must not give a value in excess of 24 hours. */
if ( h_temp >= NO_OF_HOURS_IN_A_DAY )
{
/* ERROR: Return on NULL. */
return NULL;
}
scaled_td->day = 0;
scaled_td->month = 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment