@@ -351,8 +351,10 @@ bool bc_divide_ex(bc_num numerator, bc_num divisor, bc_num *quot, bc_num *rem, s
351
351
return false;
352
352
}
353
353
354
- bc_free_num (quot );
355
354
size_t quot_scale = scale ;
355
+ if (use_quot ) {
356
+ bc_free_num (quot );
357
+ }
356
358
357
359
/* If numerator is zero, the quotient is always zero. */
358
360
if (bc_is_zero (numerator )) {
@@ -410,12 +412,14 @@ bool bc_divide_ex(bc_num numerator, bc_num divisor, bc_num *quot, bc_num *rem, s
410
412
}
411
413
412
414
size_t quot_size = numerator_size - divisor_size + 1 ; /* numerator_size >= divisor_size */
413
- if (quot_size > quot_scale ) {
414
- * quot = bc_new_num_nonzeroed (quot_size - quot_scale , quot_scale );
415
- } else {
416
- * quot = bc_new_num_nonzeroed (1 , quot_scale ); /* 1 is for 0 */
415
+ if (use_quot ) {
416
+ if (quot_size > quot_scale ) {
417
+ * quot = bc_new_num_nonzeroed (quot_size - quot_scale , quot_scale );
418
+ } else {
419
+ * quot = bc_new_num_nonzeroed (1 , quot_scale ); /* 1 is for 0 */
420
+ }
421
+ (* quot )-> n_sign = numerator -> n_sign == divisor -> n_sign ? PLUS : MINUS ;
417
422
}
418
- (* quot )-> n_sign = numerator -> n_sign == divisor -> n_sign ? PLUS : MINUS ;
419
423
420
424
/* Size that can be read from numeratorptr */
421
425
size_t numerator_readable_size = numerator -> n_len + numerator -> n_scale - numerator_leading_zeros ;
@@ -433,13 +437,18 @@ bool bc_divide_ex(bc_num numerator, bc_num divisor, bc_num *quot, bc_num *rem, s
433
437
quot , quot_size
434
438
);
435
439
436
- _bc_rm_leading_zeros (* quot );
437
- if (bc_is_zero (* quot )) {
438
- (* quot )-> n_sign = PLUS ;
440
+ if (use_quot ) {
441
+ _bc_rm_leading_zeros (* quot );
442
+ if (bc_is_zero (* quot )) {
443
+ (* quot )-> n_sign = PLUS ;
444
+ (* quot )-> n_scale = 0 ;
445
+ }
439
446
}
440
447
return true;
441
448
442
449
quot_zero :
443
- * quot = bc_copy_num (BCG (_zero_ ));
450
+ if (use_quot ) {
451
+ * quot = bc_copy_num (BCG (_zero_ ));
452
+ }
444
453
return true;
445
454
}
0 commit comments