time tests pass

This commit is contained in:
Louis Rubet 2022-02-20 17:43:49 +01:00
parent 949a1a0648
commit af5b3def4c
4 changed files with 14 additions and 17 deletions

View file

@ -67,7 +67,7 @@ add_executable(
${PROJECT_SOURCE_DIR}/src/rpn-string.cpp
${PROJECT_SOURCE_DIR}/src/rpn-test.cpp
${PROJECT_SOURCE_DIR}/src/rpn-test-framework.cpp
#${PROJECT_SOURCE_DIR}/src/rpn-time.cpp
${PROJECT_SOURCE_DIR}/src/rpn-time.cpp
${PROJECT_SOURCE_DIR}/src/rpn-trig.cpp
${PROJECT_SOURCE_DIR}/linenoise-ng/src/ConvertUTF.cpp
${PROJECT_SOURCE_DIR}/linenoise-ng/src/linenoise.cpp

View file

@ -199,10 +199,10 @@ program::keyword_t program::s_keywords[] = {
// {cmd_keyword, "atanh", &program::rpn_atanh, "inverse hyperbolic tangent"},
// TIME AND DATE
// {cmd_undef, "", NULL, "\nTIME AND DATE"},
// {cmd_keyword, "time", &program::rpn_time, "time in local format"},
// {cmd_keyword, "date", &program::rpn_date, "date in local format"},
// {cmd_keyword, "ticks", &program::rpn_ticks, "system tick in µs"},
{cmd_undef, "", NULL, "\nTIME AND DATE"},
{cmd_keyword, "time", &program::rpn_time, "time in local format"},
{cmd_keyword, "date", &program::rpn_date, "date in local format"},
{cmd_keyword, "ticks", &program::rpn_ticks, "system tick in µs"},
// end
{cmd_max, "", NULL, ""},

View file

@ -19,10 +19,9 @@ void program::rpn_time() {
((double)tm->tm_sec) * 1000000.0 + (double)(ts.tv_nsec / 1000);
// push it
number* num;
_stack->push_front(num = static_cast<number*>(new number(date)));
// division is done here because of real precision)
CHECK_MPFR(mpfr_div_d(num->_value.mpfr, num->_value.mpfr, 10000000000.0, mpreal::get_default_rnd()));
// division after push for real precision
_stack->push(new number(date));
_stack->value<number>(0) /= 10000000000.0;
} else
ERR_CONTEXT(ret_internal);
}
@ -44,9 +43,9 @@ void program::rpn_date() {
// push it
number* num;
_stack->push_front(num = static_cast<number*>(new number(date)));
// division is done here because of real precision)
CHECK_MPFR(mpfr_div_d(num->_value.mpfr, num->_value.mpfr, 1000000.0, mpreal::get_default_rnd()));
// division after push for real precision
_stack->push(new number(date));
_stack->value<number>(0) /= 1000000.0;
} else
ERR_CONTEXT(ret_internal);
}
@ -65,9 +64,7 @@ void program::rpn_ticks() {
if (tm != NULL) {
// date in µs
date = 1000000.0 * (double)ts.tv_sec + (double)(ts.tv_nsec / 1000);
// push it
_stack->push_front(static_cast<number*>(new number(date)));
_stack->push(new number(date));
} else
ERR_CONTEXT(ret_internal);
}

View file

@ -18,7 +18,7 @@
@include 080-store.md
@include 090-program.md
@include 100-complex.md
# @include 110-time.md
@include 110-time.md
# @include 120-trig.md
# @include 120-logs.md
# @include 130-logs.md
# @include 999-manual-tests.md