mirror of
https://github.com/louisrubet/rpn
synced 2025-02-01 07:57:52 +01:00
#136: Corrected some problems: dec and hex commands wrongly removed, bug in command sub, 05-real.txtand 04-stack.txt typo
This commit is contained in:
parent
855f99ed2e
commit
8944940da5
4 changed files with 18 additions and 11 deletions
|
@ -42,6 +42,8 @@ program::keyword_t program::s_keywords[] =
|
||||||
{ cmd_keyword, "sq", &program::square, "(or sqr) square" },
|
{ cmd_keyword, "sq", &program::square, "(or sqr) square" },
|
||||||
{ cmd_keyword, "sqr", &program::square, "" },
|
{ cmd_keyword, "sqr", &program::square, "" },
|
||||||
{ cmd_keyword, "abs", &program::rpn_abs, "absolute value" },
|
{ 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"
|
{ 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" },
|
"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" },
|
{ cmd_keyword, "round", &program::round, "set float rounding mode.\n\tex: [\"nearest\", \"toward zero\", \"toward +inf\", \"toward -inf\", \"away from zero\"] round" },
|
||||||
|
|
|
@ -109,7 +109,7 @@ void strsub()
|
||||||
|
|
||||||
long first = long(((number*)_stack->get_obj(1))->_value) - 1;
|
long first = long(((number*)_stack->get_obj(1))->_value) - 1;
|
||||||
long last = long(((number*)_stack->get_obj(0))->_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;
|
bool result_is_void = false;
|
||||||
|
|
||||||
_stack->pop_back();
|
_stack->pop_back();
|
||||||
|
@ -119,12 +119,17 @@ void strsub()
|
||||||
first = 0;
|
first = 0;
|
||||||
if (last < 0)
|
if (last < 0)
|
||||||
last = 0;
|
last = 0;
|
||||||
if (first > len)
|
if (first > len && last > len)
|
||||||
first = len -1;
|
|
||||||
if (last > len)
|
|
||||||
last = len -1;
|
|
||||||
if (first > last)
|
|
||||||
result_is_void=true;
|
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)
|
if (!result_is_void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,7 +35,7 @@ erase
|
||||||
erase
|
erase
|
||||||
|
|
||||||
# drop2
|
# drop2
|
||||||
3
|
1 2 3
|
||||||
drop2
|
drop2
|
||||||
-> stack size should be 1
|
-> stack size should be 1
|
||||||
-> stack should be 1
|
-> stack should be 1
|
||||||
|
@ -95,7 +95,7 @@ erase
|
||||||
depth
|
depth
|
||||||
-> stack size should be 4
|
-> stack size should be 4
|
||||||
-> stack should be 1, 2, 3, 3
|
-> stack should be 1, 2, 3, 3
|
||||||
>erase
|
erase
|
||||||
|
|
||||||
# test pick
|
# test pick
|
||||||
1 2 3 4 2 pick
|
1 2 3 4 2 pick
|
||||||
|
|
|
@ -25,7 +25,7 @@ erase
|
||||||
erase
|
erase
|
||||||
|
|
||||||
# real hex (2)
|
# real hex (2)
|
||||||
0x1.234p+12, 0x1.01p+4
|
0x1.234p+12 0x1.01p+4
|
||||||
dec swap dec swap
|
dec swap dec swap
|
||||||
-> stack should be 4660, 16.0625
|
-> stack should be 4660, 16.0625
|
||||||
erase
|
erase
|
||||||
|
@ -284,7 +284,7 @@ erase
|
||||||
|
|
||||||
# sqrt (2)
|
# sqrt (2)
|
||||||
sqrt
|
sqrt
|
||||||
-> error should be 2
|
-> error should be 3
|
||||||
|
|
||||||
# sq (1)
|
# sq (1)
|
||||||
12 sq
|
12 sq
|
||||||
|
|
Loading…
Add table
Reference in a new issue