Skip to content

Commit 6e43df5

Browse files
committed
Roughly write code using use_rem
1 parent 797fa6b commit 6e43df5

File tree

1 file changed

+23
-1
lines changed
  • ext/bcmath/libbcmath/src

1 file changed

+23
-1
lines changed

ext/bcmath/libbcmath/src/div.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,17 @@ bool bc_divide_ex(bc_num numerator, bc_num divisor, bc_num *quot, bc_num *rem, s
342342
return false;
343343
}
344344

345-
size_t quot_scale = scale;
345+
size_t quot_scale = 0;
346+
size_t rem_scale = 0;
346347
if (use_quot) {
347348
bc_free_num(quot);
348349
}
350+
if (use_rem) {
351+
bc_free_num(rem);
352+
rem_scale = scale;
353+
} else {
354+
quot_scale = scale;
355+
}
349356

350357
/* If numerator is zero, the quotient is always zero. */
351358
if (bc_is_zero(numerator)) {
@@ -412,6 +419,10 @@ bool bc_divide_ex(bc_num numerator, bc_num divisor, bc_num *quot, bc_num *rem, s
412419
(*quot)->n_sign = numerator->n_sign == divisor->n_sign ? PLUS : MINUS;
413420
}
414421

422+
if (use_rem) {
423+
/* TODO: create bc_num for rem */
424+
}
425+
415426
/* Size that can be read from numeratorptr */
416427
size_t numerator_readable_size = numerator->n_len + numerator->n_scale - numerator_leading_zeros;
417428

@@ -435,11 +446,22 @@ bool bc_divide_ex(bc_num numerator, bc_num divisor, bc_num *quot, bc_num *rem, s
435446
(*quot)->n_scale = 0;
436447
}
437448
}
449+
if (use_rem) {
450+
_bc_rm_leading_zeros(*rem);
451+
if (bc_is_zero(*rem)) {
452+
(*rem)->n_sign = PLUS;
453+
(*rem)->n_scale = 0;
454+
}
455+
}
438456
return true;
439457

440458
quot_zero:
441459
if (use_quot) {
442460
*quot = bc_copy_num(BCG(_zero_));
443461
}
462+
if (use_rem) {
463+
bc_divide_copy_numerator(numerator, rem, rem_scale);
464+
(*rem)->n_sign = numerator->n_sign;
465+
}
444466
return true;
445467
}

0 commit comments

Comments
 (0)