bugfix for exponents > 127 getting printed as negative
This commit is contained in:
parent
f7da807dd4
commit
56e3034f9d
@ -700,7 +700,7 @@ void mult_decn(void){
|
|||||||
//calculate new exponent
|
//calculate new exponent
|
||||||
new_exponent = get_exponent(&AccDecn) + get_exponent(&BDecn);
|
new_exponent = get_exponent(&AccDecn) + get_exponent(&BDecn);
|
||||||
#ifdef DEBUG_MULT
|
#ifdef DEBUG_MULT
|
||||||
printf("\n new exponent: %d:", new_exponent);
|
printf("\n new exponent: %d, is_neg: %u", new_exponent, is_neg);
|
||||||
#endif
|
#endif
|
||||||
//do multiply
|
//do multiply
|
||||||
for (i = DEC80_NUM_LSU - 1; i >= 0; i--){
|
for (i = DEC80_NUM_LSU - 1; i >= 0; i--){
|
||||||
@ -755,6 +755,9 @@ void mult_decn(void){
|
|||||||
TmpDecn.lsu[0] += carry*10;
|
TmpDecn.lsu[0] += carry*10;
|
||||||
}
|
}
|
||||||
//set new exponent, checking for over/underflow
|
//set new exponent, checking for over/underflow
|
||||||
|
#ifdef DEBUG_MULT
|
||||||
|
printf("\n new exponent: %d, is_neg: %u\n", new_exponent, is_neg);
|
||||||
|
#endif
|
||||||
if (new_exponent < DEC80_MAX_EXP && new_exponent > DEC80_MIN_EXP){
|
if (new_exponent < DEC80_MAX_EXP && new_exponent > DEC80_MIN_EXP){
|
||||||
set_exponent(&TmpDecn, new_exponent, is_neg);
|
set_exponent(&TmpDecn, new_exponent, is_neg);
|
||||||
} else {
|
} else {
|
||||||
@ -1359,7 +1362,7 @@ int8_t decn_to_str(const dec80* x){
|
|||||||
//print exponent
|
//print exponent
|
||||||
if (use_sci){
|
if (use_sci){
|
||||||
//check for overflow
|
//check for overflow
|
||||||
if (exponent > DEC80_MAX_EXP || exponent < DEC80_MIN_EXP){
|
if (exponent > DECN_MAX_PRINT_EXP || exponent < DECN_MIN_PRINT_EXP){
|
||||||
set_str_error();
|
set_str_error();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,9 @@ typedef int8_t exp_t;
|
|||||||
#define DEC80_NAN_EXP (-63 - 1) //-64
|
#define DEC80_NAN_EXP (-63 - 1) //-64
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//for printing: exponent gets returned as int8_t
|
||||||
|
#define DECN_MIN_PRINT_EXP (-128)
|
||||||
|
#define DECN_MAX_PRINT_EXP 128
|
||||||
|
|
||||||
//decimal80 unpacked into 80 bits
|
//decimal80 unpacked into 80 bits
|
||||||
// for computation
|
// for computation
|
||||||
|
Loading…
Reference in New Issue
Block a user