@@ -314,9 +314,10 @@ static inline void bc_divide_copy_numerator(bc_num numerator, bc_num *num, size_
314314 memcpy ((* num )-> n_value , numerator -> n_value , numerator -> n_len + scale );
315315}
316316
317- static inline void bc_divide_by_one (bc_num numerator , bc_num * quot , size_t quot_scale )
317+ static inline void bc_divide_by_one (bc_num numerator , bc_num divisor , bc_num * quot , size_t quot_scale )
318318{
319319 bc_divide_copy_numerator (numerator , quot , quot_scale );
320+ (* quot )-> n_sign = numerator -> n_sign == divisor -> n_sign ? PLUS : MINUS ;
320321}
321322
322323static inline void bc_divide_by_pow_10 (
@@ -360,8 +361,7 @@ bool bc_divide_ex(bc_num numerator, bc_num divisor, bc_num *quot, bc_num *rem, s
360361
361362 /* If divisor is 1 / -1, the quotient's n_value is equal to numerator's n_value. */
362363 if (_bc_do_compare (divisor , BCG (_one_ ), divisor -> n_scale , false) == BCMATH_EQUAL ) {
363- bc_divide_by_one (numerator , quot , quot_scale );
364- (* quot )-> n_sign = numerator -> n_sign == divisor -> n_sign ? PLUS : MINUS ;
364+ bc_divide_by_one (numerator , divisor , quot , quot_scale );
365365 return true;
366366 }
367367
@@ -415,14 +415,14 @@ bool bc_divide_ex(bc_num numerator, bc_num divisor, bc_num *quot, bc_num *rem, s
415415 } else {
416416 * quot = bc_new_num_nonzeroed (1 , quot_scale ); /* 1 is for 0 */
417417 }
418+ (* quot )-> n_sign = numerator -> n_sign == divisor -> n_sign ? PLUS : MINUS ;
418419
419420 /* Size that can be read from numeratorptr */
420421 size_t numerator_readable_size = numerator -> n_len + numerator -> n_scale - numerator_leading_zeros ;
421422
422423 /* If divisor is 1 here, return the result of adjusting the decimal point position of numerator. */
423424 if (divisor_size == 1 && * divisorptr == 1 ) {
424425 bc_divide_by_pow_10 (numeratorptr , numerator_readable_size , quot , quot_size , quot_scale );
425- (* quot )-> n_sign = numerator -> n_sign == divisor -> n_sign ? PLUS : MINUS ;
426426 return true;
427427 }
428428
@@ -436,8 +436,6 @@ bool bc_divide_ex(bc_num numerator, bc_num divisor, bc_num *quot, bc_num *rem, s
436436 _bc_rm_leading_zeros (* quot );
437437 if (bc_is_zero (* quot )) {
438438 (* quot )-> n_sign = PLUS ;
439- } else {
440- (* quot )-> n_sign = numerator -> n_sign == divisor -> n_sign ? PLUS : MINUS ;
441439 }
442440 return true;
443441
0 commit comments