@@ -346,8 +346,10 @@ bool bc_divide_ex(bc_num numerator, bc_num divisor, bc_num *quot, bc_num *rem, s
346
346
return false;
347
347
}
348
348
349
- bc_free_num (quot );
350
349
size_t quot_scale = scale ;
350
+ if (use_quot ) {
351
+ bc_free_num (quot );
352
+ }
351
353
352
354
/* If numerator is zero, the quotient is always zero. */
353
355
if (bc_is_zero (numerator )) {
@@ -399,12 +401,14 @@ bool bc_divide_ex(bc_num numerator, bc_num divisor, bc_num *quot, bc_num *rem, s
399
401
numerator_size -= divisor_trailing_zeros ;
400
402
401
403
size_t quot_size = numerator_size - divisor_size + 1 ; /* numerator_size >= divisor_size */
402
- if (quot_size > quot_scale ) {
403
- * quot = bc_new_num_nonzeroed (quot_size - quot_scale , quot_scale );
404
- } else {
405
- * quot = bc_new_num_nonzeroed (1 , quot_scale ); /* 1 is for 0 */
404
+ if (use_quot ) {
405
+ if (quot_size > quot_scale ) {
406
+ * quot = bc_new_num_nonzeroed (quot_size - quot_scale , quot_scale );
407
+ } else {
408
+ * quot = bc_new_num_nonzeroed (1 , quot_scale ); /* 1 is for 0 */
409
+ }
410
+ (* quot )-> n_sign = numerator -> n_sign == divisor -> n_sign ? PLUS : MINUS ;
406
411
}
407
- (* quot )-> n_sign = numerator -> n_sign == divisor -> n_sign ? PLUS : MINUS ;
408
412
409
413
/* Size that can be read from numeratorptr */
410
414
size_t numerator_readable_size = numerator -> n_len + numerator -> n_scale - numerator_leading_zeros ;
@@ -422,13 +426,18 @@ bool bc_divide_ex(bc_num numerator, bc_num divisor, bc_num *quot, bc_num *rem, s
422
426
quot , quot_size
423
427
);
424
428
425
- _bc_rm_leading_zeros (* quot );
426
- if (bc_is_zero (* quot )) {
427
- (* quot )-> n_sign = PLUS ;
429
+ if (use_quot ) {
430
+ _bc_rm_leading_zeros (* quot );
431
+ if (bc_is_zero (* quot )) {
432
+ (* quot )-> n_sign = PLUS ;
433
+ (* quot )-> n_scale = 0 ;
434
+ }
428
435
}
429
436
return true;
430
437
431
438
quot_zero :
432
- * quot = bc_copy_num (BCG (_zero_ ));
439
+ if (use_quot ) {
440
+ * quot = bc_copy_num (BCG (_zero_ ));
441
+ }
433
442
return true;
434
443
}
0 commit comments