Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libmtime
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
icon-libraries
libmtime
Commits
6117b402
Commit
6117b402
authored
5 years ago
by
Florian Prill
Committed by
Luis Kornblueh
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
timedelta divide: no negative divisor allowed; restructured return code.
parent
0964baab
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/mtime_timedelta.c
+53
-46
53 additions, 46 deletions
src/mtime_timedelta.c
with
53 additions
and
46 deletions
src/mtime_timedelta.c
+
53
−
46
View file @
6117b402
...
...
@@ -1177,63 +1177,70 @@ struct _divisionquotienttimespan*
divideTimeDelta
(
struct
_timedelta
*
dividend
,
struct
_timedelta
*
divisor
,
struct
_datetime
*
base_dt
,
struct
_divisionquotienttimespan
*
quo_ret
)
{
if
((
dividend
==
NULL
)
||
(
divisor
==
NULL
)
||
(
quo_ret
==
NULL
))
return
NULL
;
struct
_divisionquotienttimespan
*
ret
=
quo_ret
;
struct
_juliandelta
*
jd_dividend
=
NULL
,
*
jd_divisor
=
NULL
;
if
((
dividend
==
NULL
)
||
(
divisor
==
NULL
)
||
(
quo_ret
==
NULL
))
ret
=
NULL
;
/* convert dividend and divisor into _juliandelta data type. */
struct
_juliandelta
*
jd_dividend
=
newJulianDelta
(
'+'
,
0
,
0
);
if
(
jd_dividend
=
=
NULL
)
return
NULL
;
jd_dividend
=
timeDeltaToJulianDelta
(
dividend
,
base_dt
,
jd_dividend
)
;
if
(
jd_dividend
=
=
NULL
)
{
deallocateJulianDelta
(
jd_dividend
);
return
NULL
;
if
(
ret
!=
NULL
)
{
jd_dividend
=
newJulianDelta
(
'+'
,
0
,
0
)
;
if
(
jd_dividend
==
NULL
)
ret
=
NULL
;
else
{
jd_dividend
=
timeDeltaToJulianDelta
(
dividend
,
base_dt
,
jd_dividend
);
if
(
jd_dividend
==
NULL
)
ret
=
NULL
;
}
}
struct
_juliandelta
*
jd_divisor
=
newJulianDelta
(
'+'
,
0
,
0
);
if
(
jd_divisor
=
=
NULL
)
return
NULL
;
jd_divisor
=
timeDeltaToJulianDelta
(
divisor
,
base_dt
,
jd_divisor
)
;
if
(
jd_divisor
=
=
NULL
)
{
deallocateJulianDelta
(
jd_divisor
);
return
NULL
;
if
(
ret
!=
NULL
)
{
jd_divisor
=
newJulianDelta
(
'+'
,
0
,
0
)
;
if
(
jd_divisor
==
NULL
)
ret
=
NULL
;
else
{
jd_divisor
=
timeDeltaToJulianDelta
(
divisor
,
base_dt
,
jd_divisor
);
if
((
jd_divisor
==
NULL
)
||
(
jd_divisor
->
sign
==
'-'
))
ret
=
NULL
;
}
/* perform large integer division. */
t_int
days1
,
day_fraction1
,
days2
,
day_fraction2
;
t_int
q_decimal
=
0
,
remainder_days
=
0
,
remainder_ms
=
0
;
days1
=
(
t_int
)
jd_dividend
->
day
;
day_fraction1
=
(
t_int
)
jd_dividend
->
ms
;
days2
=
(
t_int
)
jd_divisor
->
day
;
day_fraction2
=
(
t_int
)
jd_divisor
->
ms
;
int
ret
=
divide_timespan
(
days1
,
day_fraction1
,
days2
,
day_fraction2
,
&
q_decimal
,
&
remainder_days
,
&
remainder_ms
);
quo_ret
->
quotient
=
(
int64_t
)
0
;
quo_ret
->
remainder_days
=
(
int64_t
)
0
;
quo_ret
->
remainder_in_ms
=
(
int64_t
)
0
;
if
(
ret
==
0
)
{
quo_ret
->
quotient
=
(
int64_t
)
q_decimal
;
quo_ret
->
remainder_days
=
(
int64_t
)
remainder_days
;
quo_ret
->
remainder_in_ms
=
(
int64_t
)
remainder_ms
;
}
/* correct sign. */
/* TODO: maybe we should better remove negative time span division. Is it well-defined? */
if
(
jd_dividend
->
sign
!=
jd_divisor
->
sign
)
{
quo_ret
->
quotient
*=
-
1
;
quo_ret
->
remainder_days
*=
-
1
;
quo_ret
->
remainder_in_ms
*=
-
1
;
if
(
ret
!=
NULL
)
{
/* perform large integer division. */
t_int
days1
,
day_fraction1
,
days2
,
day_fraction2
;
t_int
q_decimal
=
0
,
remainder_days
=
0
,
remainder_ms
=
0
;
days1
=
(
t_int
)
jd_dividend
->
day
;
day_fraction1
=
(
t_int
)
jd_dividend
->
ms
;
days2
=
(
t_int
)
jd_divisor
->
day
;
day_fraction2
=
(
t_int
)
jd_divisor
->
ms
;
int
iret
=
divide_timespan
(
days1
,
day_fraction1
,
days2
,
day_fraction2
,
&
q_decimal
,
&
remainder_days
,
&
remainder_ms
);
quo_ret
->
quotient
=
(
int64_t
)
0
;
quo_ret
->
remainder_days
=
(
int64_t
)
0
;
quo_ret
->
remainder_in_ms
=
(
int64_t
)
0
;
if
(
iret
!=
0
)
ret
=
NULL
;
else
{
quo_ret
->
quotient
=
(
int64_t
)
q_decimal
;
quo_ret
->
remainder_days
=
(
int64_t
)
remainder_days
;
quo_ret
->
remainder_in_ms
=
(
int64_t
)
remainder_ms
;
}
}
deallocateJulianDelta
(
jd_dividend
);
deallocateJulianDelta
(
jd_divisor
);
if
(
ret
!=
NULL
)
{
if
(
jd_dividend
->
sign
==
'-'
)
{
/* correct sign. */
quo_ret
->
quotient
*=
-
1
;
quo_ret
->
remainder_days
*=
-
1
;
quo_ret
->
remainder_in_ms
*=
-
1
;
}
}
if
(
ret
!=
0
)
return
NULL
;
if
(
jd_dividend
!=
NULL
)
deallocateJulianDelta
(
jd_dividend
);
if
(
jd_divisor
!=
NULL
)
deallocateJulianDelta
(
jd_divisor
);
return
(
quo_
ret
)
;
return
ret
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment