Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
95fa22a6
Commit
95fa22a6
authored
Jun 15, 2015
by
Lukas Joeressen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rounding errors could make time_alloc imprecise
parent
97a18ff4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
2 deletions
+11
-2
mrbgems/mruby-time/src/time.c
mrbgems/mruby-time/src/time.c
+3
-2
mrbgems/mruby-time/test/time.rb
mrbgems/mruby-time/test/time.rb
+8
-0
No files found.
mrbgems/mruby-time/src/time.c
View file @
95fa22a6
...
...
@@ -6,6 +6,7 @@
#include <stdio.h>
#include <time.h>
#include <math.h>
#include "mruby.h"
#include "mruby/class.h"
#include "mruby/data.h"
...
...
@@ -208,12 +209,12 @@ time_alloc(mrb_state *mrb, double sec, double usec, enum mrb_timezone timezone)
out_of_range:
mrb_raisef
(
mrb
,
E_ARGUMENT_ERROR
,
"%S out of Time range"
,
mrb_float_value
(
mrb
,
sec
));
}
tm
->
usec
=
(
time_t
)((
sec
-
tm
->
sec
)
*
1.0e6
+
usec
);
tm
->
usec
=
(
time_t
)
llrint
((
sec
-
tm
->
sec
)
*
1.0e6
+
usec
);
while
(
tm
->
usec
<
0
)
{
tm
->
sec
--
;
tm
->
usec
+=
1000000
;
}
while
(
tm
->
usec
>
1000000
)
{
while
(
tm
->
usec
>
=
1000000
)
{
tm
->
sec
++
;
tm
->
usec
-=
1000000
;
}
...
...
mrbgems/mruby-time/test/time.rb
View file @
95fa22a6
...
...
@@ -203,3 +203,11 @@ assert('day of week methods') do
assert_false
t
.
friday?
assert_false
t
.
saturday?
end
assert
(
'2000 times 500us make a second'
)
do
t
=
Time
.
utc
2015
2000
.
times
do
t
+=
0.0005
end
t
.
usec
==
0
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment