handle truncation in entering numbers properly

This commit is contained in:
Mirko Scholz 2020-09-05 10:43:28 +02:00
parent 6ab4cfb714
commit 51c2d2e2e7
2 changed files with 4 additions and 1 deletions

View File

@ -316,7 +316,6 @@ void build_dec80(__xdata const char* signif_str, __xdata exp_t exponent){
// adjust exponent for left-aligned significand input
// or for number of digits past decimal point
if (num_lr_points > 0){ //left count exists
assert(DEC80_NUM_LSU*2 > num_lr_points);
new_exponent = exponent + (num_lr_points - 1); //1 digit left of implicit point
//overflow is checked later, should be impossible to overflow int16_t:
assert(new_exponent >= exponent);

View File

@ -110,6 +110,10 @@ TEST_CASE("build decn"){
decn_to_str_complete(&AccDecn);
CHECK_THAT(Buf, Equals("123456789012345678."));
build_dec80("12345678901234567890", +2);
decn_to_str_complete(&AccDecn);
CHECK_THAT(Buf, Equals("1.23456789012345678E21"));
//overflow
build_dec80("100", DEC80_MAX_EXP-1);
decn_to_str_complete(&AccDecn);