Skip to content

Commit 19e09bb

Browse files
committed
moved POW_10_LUT to private.h
1 parent 884e909 commit 19e09bb

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

ext/bcmath/libbcmath/src/div.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@
3737
#include <string.h>
3838
#include "zend_alloc.h"
3939

40-
static const BC_VECTOR POW_10_LUT[9] = {
41-
1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000
42-
};
43-
4440
/*
4541
* This function should be used when the divisor is not split into multiple chunks, i.e. when the size of the array is one.
4642
* This is because the algorithm can be simplified.
@@ -174,8 +170,8 @@ static inline void bc_standard_div(
174170
divisor_top_digits = BC_VECTOR_SIZE;
175171
}
176172

177-
size_t high_part_shift = POW_10_LUT[BC_VECTOR_SIZE - divisor_top_digits + 1];
178-
size_t low_part_shift = POW_10_LUT[divisor_top_digits - 1];
173+
size_t high_part_shift = BC_POW_10_LUT[BC_VECTOR_SIZE - divisor_top_digits + 1];
174+
size_t low_part_shift = BC_POW_10_LUT[divisor_top_digits - 1];
179175
BC_VECTOR divisor_high_part = divisor_vectors[divisor_top_index] * high_part_shift + divisor_vectors[divisor_top_index - 1] / low_part_shift;
180176
for (size_t i = 0; i < quot_arr_size; i++) {
181177
BC_VECTOR numerator_high_part = numerator_vectors[numerator_top_index - i] * high_part_shift + numerator_vectors[numerator_top_index - i - 1] / low_part_shift;
@@ -281,7 +277,7 @@ static void bc_do_div(
281277
size_t numerator_read = 0;
282278
if (numerator_bottom_read_len < BC_VECTOR_SIZE) {
283279
numerator_read = MIN(numerator_bottom_read_len, numerator_readable_len);
284-
base = POW_10_LUT[numerator_bottom_extension];
280+
base = BC_POW_10_LUT[numerator_bottom_extension];
285281
numerator_vectors[numerator_vector_count] = 0;
286282
for (size_t i = 0; i < numerator_read; i++) {
287283
numerator_vectors[numerator_vector_count] += *numerator * base;

ext/bcmath/libbcmath/src/private.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
#include <stddef.h>
3636
#include "zend_portability.h"
3737

38+
#ifndef _BCMATH_PRIV_H_
39+
#define _BCMATH_PRIV_H_
40+
3841
/* This will be 0x01010101 for 32-bit and 0x0101010101010101 for 64-bit */
3942
#define SWAR_ONES (~((size_t) 0) / 0xFF)
4043
/* This repeats a byte `x` into an entire 32/64-bit word.
@@ -67,9 +70,15 @@
6770
*/
6871
#define BC_VECTOR_NO_OVERFLOW_ADD_COUNT (~((BC_VECTOR) 0) / (BC_VECTOR_BOUNDARY_NUM * BC_VECTOR_BOUNDARY_NUM))
6972

73+
static const BC_VECTOR BC_POW_10_LUT[9] = {
74+
1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000
75+
};
76+
7077

7178
/* routines */
7279
bcmath_compare_result _bc_do_compare (bc_num n1, bc_num n2, size_t scale, bool use_sign);
7380
bc_num _bc_do_add (bc_num n1, bc_num n2);
7481
bc_num _bc_do_sub (bc_num n1, bc_num n2);
7582
void _bc_rm_leading_zeros (bc_num num);
83+
84+
#endif

0 commit comments

Comments
 (0)