File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed
Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -77,19 +77,22 @@ bool bc_sqrt(bc_num *num, size_t scale)
7777 if ((* num )-> n_len + (rscale + 1 ) * 2 < sizeof (LONG_MIN_DIGITS ) - 1 ) {
7878 /* fast path */
7979
80- /* Calculate the initial guess. */
81- BC_VECTOR guess_vector = 1 ;
82- if (num_cmp_one != BCMATH_RIGHT_GREATER ) {
83- guess_vector *= bc_sqrt_get_pow_10 (((* num )-> n_len + rscale + 1 ) >> 1 );
84- }
85-
8680 BC_VECTOR n_vector = 0 ;
8781 size_t i = 0 ;
8882 for (; i < (* num )-> n_len + (* num )-> n_scale ; i ++ ) {
8983 n_vector = n_vector * BASE + (* num )-> n_value [i ];
9084 }
9185 n_vector *= bc_sqrt_get_pow_10 ((rscale + 1 ) * 2 - (* num )-> n_scale );
9286
87+ /* Calculate the initial guess. */
88+ union {
89+ uint64_t i ;
90+ double d ;
91+ } u ;
92+ u .d = (double ) n_vector ;
93+ u .i = (1ULL << 61 ) + (u .i >> 1 ) - (1ULL << 50 );
94+ BC_VECTOR guess_vector = (BC_VECTOR ) u .d ;
95+
9396 BC_VECTOR guess1_vector ;
9497 bool done = false;
9598 while (!done ) {
You can’t perform that action at this time.
0 commit comments