@@ -340,7 +340,10 @@ static inline void bc_divide_by_one(
340
340
}
341
341
342
342
static inline void bc_divide_by_pow_10 (
343
- const char * numeratorptr , size_t numerator_readable_size , bc_num * quot , size_t quot_size , size_t quot_scale , bool use_quot )
343
+ const char * numeratorptr , size_t numerator_readable_size , size_t numerator_leading_zeros ,
344
+ bc_num * quot , size_t quot_size , size_t quot_scale , bool use_quot ,
345
+ bc_num * rem , size_t rem_size , bool use_rem ,
346
+ size_t numerator_rem_len_diff )
344
347
{
345
348
if (use_quot ) {
346
349
char * qptr = (* quot )-> n_value ;
@@ -363,6 +366,23 @@ static inline void bc_divide_by_pow_10(
363
366
(* quot )-> n_scale -= qend - qptr ;
364
367
}
365
368
}
369
+ if (use_rem ) {
370
+ size_t rem_leading_zeros = numerator_leading_zeros + quot_size - numerator_rem_len_diff ;
371
+ if (rem_size <= rem_leading_zeros ) {
372
+ bc_free_num (rem );
373
+ * rem = bc_copy_num (BCG (_zero_ ));
374
+ return ;
375
+ }
376
+ /* The values after this have already been copied, so just need to set them to 0. */
377
+ for (size_t i = 0 ; i < rem_leading_zeros ; i ++ ) {
378
+ (* rem )-> n_value [i ] = 0 ;
379
+ }
380
+ _bc_rm_leading_zeros (* rem );
381
+ if (bc_is_zero (* rem )) {
382
+ (* rem )-> n_sign = PLUS ;
383
+ (* rem )-> n_scale = 0 ;
384
+ }
385
+ }
366
386
}
367
387
368
388
bool bc_divide_ex (bc_num numerator , bc_num divisor , bc_num * quot , bc_num * rem , size_t scale , bool use_quot , bool use_rem )
@@ -492,7 +512,11 @@ bool bc_divide_ex(bc_num numerator, bc_num divisor, bc_num *quot, bc_num *rem, s
492
512
493
513
/* If divisor is 1 here, return the result of adjusting the decimal point position of numerator. */
494
514
if (divisor_size == 1 && * divisorptr == 1 ) {
495
- bc_divide_by_pow_10 (numeratorptr , numerator_readable_size , quot , quot_size , quot_scale );
515
+ bc_divide_by_pow_10 (
516
+ numeratorptr , numerator_readable_size , numerator_leading_zeros ,
517
+ quot , quot_size , quot_scale , use_quot ,
518
+ rem , rem_size , use_rem , numerator_rem_len_diff
519
+ );
496
520
return true;
497
521
}
498
522
0 commit comments