Skip to content

Commit 22b6adb

Browse files
committed
Optimized and changed the initialization process to run a little later.
1 parent 684e6d2 commit 22b6adb

File tree

1 file changed

+6
-7
lines changed
  • ext/bcmath/libbcmath/src

1 file changed

+6
-7
lines changed

ext/bcmath/libbcmath/src/sqrt.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,9 @@ bool bc_sqrt(bc_num *num, size_t scale)
6060

6161
/* Initialize the variables. */
6262
size_t cscale;
63-
bc_num guess, guess1, point5, diff;
63+
bc_num guess;
6464
size_t rscale = MAX(scale, (*num)->n_scale);
6565

66-
bc_init_num(&guess1);
67-
bc_init_num(&diff);
68-
point5 = bc_new_num (1, 1);
69-
point5->n_value[1] = 5;
70-
71-
7266
/* Calculate the initial guess. */
7367
if (num_cmp_one == BCMATH_RIGHT_GREATER) {
7468
/* The number is between 0 and 1. Guess should start at 1. */
@@ -87,6 +81,11 @@ bool bc_sqrt(bc_num *num, size_t scale)
8781
cscale = 3;
8882
}
8983

84+
bc_num guess1 = NULL;
85+
bc_num point5 = bc_new_num (1, 1);
86+
point5->n_value[1] = 5;
87+
bc_num diff = NULL;
88+
9089
/* Find the square root using Newton's algorithm. */
9190
bool done = false;
9291
while (!done) {

0 commit comments

Comments
 (0)