@@ -330,7 +330,10 @@ static inline void bc_divide_by_one(
330
330
}
331
331
332
332
static inline void bc_divide_by_pow_10 (
333
- const char * numeratorptr , size_t numerator_readable_size , bc_num * quot , size_t quot_size , size_t quot_scale , bool use_quot )
333
+ const char * numeratorptr , size_t numerator_readable_size , size_t numerator_leading_zeros ,
334
+ bc_num * quot , size_t quot_size , size_t quot_scale , bool use_quot ,
335
+ bc_num * rem , size_t rem_size , bool use_rem ,
336
+ size_t numerator_rem_len_diff )
334
337
{
335
338
if (use_quot ) {
336
339
char * qptr = (* quot )-> n_value ;
@@ -353,6 +356,23 @@ static inline void bc_divide_by_pow_10(
353
356
(* quot )-> n_scale -= qend - qptr ;
354
357
}
355
358
}
359
+ if (use_rem ) {
360
+ size_t rem_leading_zeros = numerator_leading_zeros + quot_size - numerator_rem_len_diff ;
361
+ if (rem_size <= rem_leading_zeros ) {
362
+ bc_free_num (rem );
363
+ * rem = bc_copy_num (BCG (_zero_ ));
364
+ return ;
365
+ }
366
+ /* The values after this have already been copied, so just need to set them to 0. */
367
+ for (size_t i = 0 ; i < rem_leading_zeros ; i ++ ) {
368
+ (* rem )-> n_value [i ] = 0 ;
369
+ }
370
+ _bc_rm_leading_zeros (* rem );
371
+ if (bc_is_zero (* rem )) {
372
+ (* rem )-> n_sign = PLUS ;
373
+ (* rem )-> n_scale = 0 ;
374
+ }
375
+ }
356
376
}
357
377
358
378
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 )
@@ -484,7 +504,11 @@ bool bc_divide_ex(bc_num numerator, bc_num divisor, bc_num *quot, bc_num *rem, s
484
504
485
505
/* If divisor is 1 here, return the result of adjusting the decimal point position of numerator. */
486
506
if (divisor_size == 1 && * divisorptr == 1 ) {
487
- bc_divide_by_pow_10 (numeratorptr , numerator_readable_size , quot , quot_size , quot_scale );
507
+ bc_divide_by_pow_10 (
508
+ numeratorptr , numerator_readable_size , numerator_leading_zeros ,
509
+ quot , quot_size , quot_scale , use_quot ,
510
+ rem , rem_size , use_rem , numerator_rem_len_diff
511
+ );
488
512
return true;
489
513
}
490
514
0 commit comments