From 8944940da5ce3aa59a8a52ff0a578486e91ffd8c Mon Sep 17 00:00:00 2001 From: Louis Rubet Date: Sun, 18 Jun 2017 15:08:03 +0200 Subject: [PATCH] #136: Corrected some problems: dec and hex commands wrongly removed, bug in command sub, 05-real.txtand 04-stack.txt typo --- src/program.cpp | 2 ++ src/rpn-string.hpp | 19 ++++++++++++------- test/04-stack.txt | 4 ++-- test/05-real.txt | 4 ++-- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/program.cpp b/src/program.cpp index cd73cb6..6fa2257 100644 --- a/src/program.cpp +++ b/src/program.cpp @@ -42,6 +42,8 @@ program::keyword_t program::s_keywords[] = { cmd_keyword, "sq", &program::square, "(or sqr) square" }, { cmd_keyword, "sqr", &program::square, "" }, { cmd_keyword, "abs", &program::rpn_abs, "absolute value" }, + { cmd_keyword, "dec", &program::dec, "decimal representation" }, + { cmd_keyword, "hex", &program::hex, "hexadecimal representation" }, { cmd_keyword, "prec", &program::precision, "get float precision in bits when first stack is not a number\n\t" "set float precision in bits when first stack entry is a number. ex: 256 prec" }, { cmd_keyword, "round", &program::round, "set float rounding mode.\n\tex: [\"nearest\", \"toward zero\", \"toward +inf\", \"toward -inf\", \"away from zero\"] round" }, diff --git a/src/rpn-string.hpp b/src/rpn-string.hpp index 64a4736..f48756d 100644 --- a/src/rpn-string.hpp +++ b/src/rpn-string.hpp @@ -109,9 +109,9 @@ void strsub() long first = long(((number*)_stack->get_obj(1))->_value) - 1; long last = long(((number*)_stack->get_obj(0))->_value) - 1; - long len = ((ostring*)_stack->get_obj(0))->_len; + long len = ((ostring*)_stack->get_obj(2))->_len; bool result_is_void = false; - + _stack->pop_back(); _stack->pop_back(); @@ -119,12 +119,17 @@ void strsub() first = 0; if (last < 0) last = 0; - if (first > len) - first = len -1; - if (last > len) - last = len -1; - if (first > last) + if (first > len && last > len) result_is_void=true; + else + { + if (first > len) + first = len -1; + if (last > len) + last = len -1; + if (first > last) + result_is_void=true; + } if (!result_is_void) { diff --git a/test/04-stack.txt b/test/04-stack.txt index 16b7bfe..e8bfd5a 100644 --- a/test/04-stack.txt +++ b/test/04-stack.txt @@ -35,7 +35,7 @@ erase erase # drop2 -3 +1 2 3 drop2 -> stack size should be 1 -> stack should be 1 @@ -95,7 +95,7 @@ erase depth -> stack size should be 4 -> stack should be 1, 2, 3, 3 ->erase +erase # test pick 1 2 3 4 2 pick diff --git a/test/05-real.txt b/test/05-real.txt index 56cafb5..4106c71 100644 --- a/test/05-real.txt +++ b/test/05-real.txt @@ -25,7 +25,7 @@ erase erase # real hex (2) -0x1.234p+12, 0x1.01p+4 +0x1.234p+12 0x1.01p+4 dec swap dec swap -> stack should be 4660, 16.0625 erase @@ -284,7 +284,7 @@ erase # sqrt (2) sqrt --> error should be 2 +-> error should be 3 # sq (1) 12 sq