summaryrefslogtreecommitdiff
path: root/test/data
diff options
context:
space:
mode:
authorPhilipp Stephani <phst@google.com>2019-04-24 13:41:05 +0200
committerPhilipp Stephani <phst@google.com>2019-04-24 13:41:05 +0200
commitc4bacb1215bfdf058b374312256c27eaea1304a4 (patch)
tree2811b773f41d6ccf6984821e89b360a48a4589b3 /test/data
parent534c33cf375182c97291d2dd242f936df5953321 (diff)
downloademacs-c4bacb1215bfdf058b374312256c27eaea1304a4.tar.gz
Clarify rounding mode when converting to struct timespec.
* doc/lispref/internals.texi (Module Values): Clarify that the truncation is towards negative infinity. * test/data/emacs-module/mod-test.c (Fmod_test_nanoseconds): Add test function. (emacs_module_init): Define it. * test/src/emacs-module-tests.el (mod-test-nanoseconds): New unit test.
Diffstat (limited to 'test/data')
-rw-r--r--test/data/emacs-module/mod-test.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/data/emacs-module/mod-test.c b/test/data/emacs-module/mod-test.c
index 85a7f28e50d..8ac08f71534 100644
--- a/test/data/emacs-module/mod-test.c
+++ b/test/data/emacs-module/mod-test.c
@@ -382,6 +382,22 @@ Fmod_test_add_nanosecond (emacs_env *env, ptrdiff_t nargs, emacs_value *args,
}
static emacs_value
+Fmod_test_nanoseconds (emacs_env *env, ptrdiff_t nargs, emacs_value *args, void *data) {
+ assert (nargs == 1);
+ struct timespec time = env->extract_time (env, args[0]);
+ struct emacs_mpz nanoseconds;
+ assert (LONG_MIN <= time.tv_sec && time.tv_sec <= LONG_MAX);
+ mpz_init_set_si (nanoseconds.value, time.tv_sec);
+ static_assert (1000000000 <= ULONG_MAX, "unsupported architecture");
+ mpz_mul_ui (nanoseconds.value, nanoseconds.value, 1000000000);
+ assert (0 <= time.tv_nsec && time.tv_nsec <= ULONG_MAX);
+ mpz_add_ui (nanoseconds.value, nanoseconds.value, time.tv_nsec);
+ emacs_value result = env->make_big_integer (env, &nanoseconds);
+ mpz_clear (nanoseconds.value);
+ return result;
+}
+
+static emacs_value
Fmod_test_double (emacs_env *env, ptrdiff_t nargs, emacs_value *args,
void *data)
{
@@ -465,6 +481,7 @@ emacs_module_init (struct emacs_runtime *ert)
NULL, NULL);
DEFUN ("mod-test-sleep-until", Fmod_test_sleep_until, 2, 2, NULL, NULL);
DEFUN ("mod-test-add-nanosecond", Fmod_test_add_nanosecond, 1, 1, NULL, NULL);
+ DEFUN ("mod-test-nanoseconds", Fmod_test_nanoseconds, 1, 1, NULL, NULL);
DEFUN ("mod-test-double", Fmod_test_double, 1, 1, NULL, NULL);
#undef DEFUN