From 21be4081b290affe73c317c591e3c1323db0c895 Mon Sep 17 00:00:00 2001 From: Jeff Wang Date: Wed, 2 Oct 2019 23:38:12 -0400 Subject: [PATCH] add log10() function --- src/calc.c | 11 ++++++++++- src/decn/decn.c | 12 +++++++++--- src/decn/decn.h | 1 + 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/calc.c b/src/calc.c index f2b7abe..90f3442 100644 --- a/src/calc.c +++ b/src/calc.c @@ -118,12 +118,21 @@ void process_cmd(char cmd){ toggle_shifted(); } break; ////////// + case '9':{ + if (IsShifted && !decn_is_nan(&stack(STACK_X))){ //log10(x) + copy_decn(&AccDecn, &stack(STACK_X)); + log10_decn(); + copy_decn(&stack(STACK_X), &AccDecn); + IsShifted = 0; + } + } break; + ////////// case '8':{ if (IsShifted && !decn_is_nan(&stack(STACK_X))){ //ln(x) copy_decn(&AccDecn, &stack(STACK_X)); ln_decn(); copy_decn(&stack(STACK_X), &AccDecn); - toggle_shifted(); + IsShifted = 0; } } break; ////////// diff --git a/src/decn/decn.c b/src/decn/decn.c index e15966a..4964bd5 100644 --- a/src/decn/decn.c +++ b/src/decn/decn.c @@ -47,9 +47,9 @@ static const uint8_t num_digits_display = 16; __idata dec80 AccDecn, BDecn; __idata dec80 TmpDecn; //used by add_decn() and mult_decn() -__idata dec80 Tmp2Decn; //used by div_decn() -__idata dec80 Tmp3Decn; //used by div_decn() -__idata dec80 Tmp4Decn; //used by div_decn() +__idata dec80 Tmp2Decn; //used by div_decn() and ln_decn() +__idata dec80 Tmp3Decn; //used by div_decn() and ln_decn() +__idata dec80 Tmp4Decn; //used by div_decn() and ln_decn() __xdata char Buf[DECN_BUF_SIZE]; @@ -1015,6 +1015,12 @@ void ln_decn(void){ #undef NUM_A_ARR } +void log10_decn(void){ + ln_decn(); + copy_decn(&BDecn, &DECN_LN_10); + div_decn(); +} + static void set_str_error(void){ Buf[0] = 'E'; Buf[1] = 'r'; diff --git a/src/decn/decn.h b/src/decn/decn.h index 22e081e..fa45ec5 100644 --- a/src/decn/decn.h +++ b/src/decn/decn.h @@ -69,6 +69,7 @@ void mult_decn(void); void div_decn(void); void ln_decn(void); +void log10_decn(void); //Buf should hold at least 18 + 4 + 5 + 1 = 28 #define DECN_BUF_SIZE 28