Skip to content

Commit b949c5e

Browse files
committed
Roughly write code using use_rem
1 parent 13a98ae commit b949c5e

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
@@ -352,10 +352,17 @@ bool bc_divide_ex(bc_num numerator, bc_num divisor, bc_num *quot, bc_num *rem, s
352352
return false;
353353
}
354354

355-
size_t quot_scale = scale;
355+
size_t quot_scale = 0;
356+
size_t rem_scale = 0;
356357
if (use_quot) {
357358
bc_free_num(quot);
358359
}
360+
if (use_rem) {
361+
bc_free_num(rem);
362+
rem_scale = scale;
363+
} else {
364+
quot_scale = scale;
365+
}
359366

360367
/* If numerator is zero, the quotient is always zero. */
361368
if (bc_is_zero(numerator)) {
@@ -416,6 +423,10 @@ bool bc_divide_ex(bc_num numerator, bc_num divisor, bc_num *quot, bc_num *rem, s
416423
(*quot)->n_sign = numerator->n_sign == divisor->n_sign ? PLUS : MINUS;
417424
}
418425

426+
if (use_rem) {
427+
/* TODO: create bc_num for rem */
428+
}
429+
419430
/* Size that can be read from numeratorptr */
420431
size_t numerator_readable_size = numerator->n_len + numerator->n_scale - numerator_leading_zeros;
421432

@@ -439,11 +450,22 @@ bool bc_divide_ex(bc_num numerator, bc_num divisor, bc_num *quot, bc_num *rem, s
439450
(*quot)->n_scale = 0;
440451
}
441452
}
453+
if (use_rem) {
454+
_bc_rm_leading_zeros(*rem);
455+
if (bc_is_zero(*rem)) {
456+
(*rem)->n_sign = PLUS;
457+
(*rem)->n_scale = 0;
458+
}
459+
}
442460
return true;
443461

444462
quot_zero:
445463
if (use_quot) {
446464
*quot = bc_copy_num(BCG(_zero_));
447465
}
466+
if (use_rem) {
467+
bc_divide_copy_numerator(numerator, rem, rem_scale);
468+
(*rem)->n_sign = numerator->n_sign;
469+
}
448470
return true;
449471
}

0 commit comments

Comments
 (0)