Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 10 Jan 2024 16:38:17 GMT
From:      Stefan =?utf-8?Q?E=C3=9Fer?= <se@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: f4fbc49d201f - main - vendor/bc: upgrade to version 6.7.5
Message-ID:  <202401101638.40AGcHGO069314@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by se:

URL: https://cgit.FreeBSD.org/src/commit/?id=f4fbc49d201f81c481a33fac6ba28e19faf96260

commit f4fbc49d201f81c481a33fac6ba28e19faf96260
Author:     Stefan Eßer <se@FreeBSD.org>
AuthorDate: 2024-01-04 23:07:46 +0000
Commit:     Stefan Eßer <se@FreeBSD.org>
CommitDate: 2024-01-10 16:36:29 +0000

    vendor/bc: upgrade to version 6.7.5
    
    This update fixes a bug that line breaks in printed numbers may not
    match the line length set by the user. The value is printed correctly,
    just not split as specified in some situations.
    
    (cherry picked from commit 52a5ec1b178fd07651446c7e31b1512794a04dbf)
---
 contrib/bc/NEWS.md                     |   9 +
 contrib/bc/include/bc.h                |   2 +-
 contrib/bc/include/history.h           |   4 -
 contrib/bc/include/num.h               |   6 +-
 contrib/bc/include/version.h           |   2 +-
 contrib/bc/scripts/sqrt_frac_guess.bc  | 126 +++++++
 contrib/bc/scripts/sqrt_int_guess.bc   |  94 +++++
 contrib/bc/scripts/sqrt_random.bc      | 129 +++++++
 contrib/bc/scripts/sqrt_random.sh      |  77 ++++
 contrib/bc/src/num.c                   |  41 ++-
 contrib/bc/src/program.c               |   4 +-
 contrib/bc/tests/bc/scripts/all.txt    |   1 +
 contrib/bc/tests/bc/scripts/print2.bc  |  63 ++++
 contrib/bc/tests/bc/scripts/print2.txt | 650 +++++++++++++++++++++++++++++++++
 contrib/bc/tests/bc/sqrt.txt           |   2 +
 contrib/bc/tests/bc/sqrt_results.txt   |   2 +
 contrib/bc/vs/bc.vcxproj               |   4 +
 contrib/bc/vs/bcl.vcxproj              |   6 +
 18 files changed, 1200 insertions(+), 22 deletions(-)

diff --git a/contrib/bc/NEWS.md b/contrib/bc/NEWS.md
index 240e02f11388..32e74de31231 100644
--- a/contrib/bc/NEWS.md
+++ b/contrib/bc/NEWS.md
@@ -1,5 +1,14 @@
 # News
 
+## 6.7.5
+
+This is a production release to fix one small bug.
+
+The bug is that sometimes numbers are printed to incorrect line lengths. The
+number is always correct; the line is just longer than the limit.
+
+Users who do not care do not need to update.
+
 ## 6.7.4
 
 This is a production release to fix problems in the `bc` manual.
diff --git a/contrib/bc/include/bc.h b/contrib/bc/include/bc.h
index 73a85aa406a0..17fd0b9d171f 100644
--- a/contrib/bc/include/bc.h
+++ b/contrib/bc/include/bc.h
@@ -276,7 +276,7 @@ bc_lex_token(BcLex* l);
  * @return   True if i is an expression token, false otherwise.
  */
 #define BC_PARSE_EXPR(i) \
-	(bc_parse_exprs[(((i) & (uchar) ~(0x07)) >> 3)] & (1 << (7 - ((i) &0x07))))
+	(bc_parse_exprs[(((i) & (uchar) ~(0x07)) >> 3)] & (1 << (7 - ((i) & 0x07))))
 
 /**
  * Returns the operator (by lex token) that is at the top of the operator
diff --git a/contrib/bc/include/history.h b/contrib/bc/include/history.h
index 19c5a0fe27f7..64402c4dffa1 100644
--- a/contrib/bc/include/history.h
+++ b/contrib/bc/include/history.h
@@ -173,10 +173,6 @@ typedef struct BcHistory
 #include <vector.h>
 #include <read.h>
 
-#if BC_DEBUG_CODE
-#include <file.h>
-#endif // BC_DEBUG_CODE
-
 /// Default columns.
 #define BC_HIST_DEF_COLS (80)
 
diff --git a/contrib/bc/include/num.h b/contrib/bc/include/num.h
index d24c206cbe51..6c9dee107f2f 100644
--- a/contrib/bc/include/num.h
+++ b/contrib/bc/include/num.h
@@ -211,9 +211,9 @@ struct BcRNG;
 #define BC_NUM_KARATSUBA_ALLOCS (6)
 
 /**
- * Rounds @a s (scale) up to the next power of BC_BASE_DIGS. This also check for
- * overflow and gives a fatal error if that happens because we just can't go
- * over the limits we have imposed.
+ * Rounds @a s (scale) up to the next power of BC_BASE_DIGS. This will also
+ * check for overflow and gives a fatal error if that happens because we just
+ * can't go over the limits we have imposed.
  * @param s  The scale to round up.
  * @return   @a s rounded up to the next power of BC_BASE_DIGS.
  */
diff --git a/contrib/bc/include/version.h b/contrib/bc/include/version.h
index d481cb10abf1..e2576269345d 100644
--- a/contrib/bc/include/version.h
+++ b/contrib/bc/include/version.h
@@ -37,6 +37,6 @@
 #define BC_VERSION_H
 
 /// The current version.
-#define VERSION 6.7.4
+#define VERSION 6.7.5
 
 #endif // BC_VERSION_H
diff --git a/contrib/bc/scripts/sqrt_frac_guess.bc b/contrib/bc/scripts/sqrt_frac_guess.bc
new file mode 100644
index 000000000000..5938cfcc7cba
--- /dev/null
+++ b/contrib/bc/scripts/sqrt_frac_guess.bc
@@ -0,0 +1,126 @@
+#! /usr/bin/bc
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (c) 2018-2023 Gavin D. Howard and contributors.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# * Redistributions of source code must retain the above copyright notice, this
+#   list of conditions and the following disclaimer.
+#
+# * Redistributions in binary form must reproduce the above copyright notice,
+#   this list of conditions and the following disclaimer in the documentation
+#   and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+scale = 20
+
+# Adjust this number to try ranges below different powers of 10.
+shift = 4
+
+# Adjust this to try extra digits. For example, a value of one means that one
+# digit is checked (such as 0.09 through 0.01), a value of two means that two
+# digits are checked (0.090 through 0.010), etc.
+max = shift + 2
+
+n = (9 >> shift)
+inc = (1 >> max)
+stop = (1 >> shift)
+
+# Uncomment this to test the high part of the ranges.
+#n += (1 - (1 >> max + 5)) >> shift
+
+for (i = n; i >= stop; i -= inc)
+{
+	# This is the lower limit.
+	t1 = sqrt(1/(3*i))
+
+	# Start with the inverse.
+	t2 = (1/i)
+
+	# And take half its length of course.
+	l = length(t2$)/2
+
+	temp = i
+	odd = 0
+
+	# We go by powers of 10 below, but there is a degenerate case: an exact
+	# power of 10, for which length() will return one digit more. So we check
+	# for that and fix it.
+	while (temp < 1)
+	{
+		temp <<= 1
+		odd = !odd
+	}
+
+	if (temp == 1)
+	{
+		odd = !odd
+	}
+
+	print "i:  ", i, "\n"
+	print "t2: ", t2, "\n"
+	#print "l:  ", l, "\n"
+	print "odd: ", odd, "\n"
+
+	if (odd)
+	{
+		# Limit between 6 and 7.5.
+		limit1 = 6.7 >> (l$ * 2 + 1)
+
+		# Limit between 1.5 and 1.83-ish.
+		limit2 = 1.7 >> (l$ * 2 + 1)
+		print "limit1: ", limit1, "\n"
+		print "limit2: ", limit2, "\n"
+
+		if (i >= limit1)
+		{
+			t2 = (t2 >> l$)
+		}
+		else if (i >= limit2)
+		{
+			t2 = (t2 >> l$) / 2
+		}
+		else
+		{
+			t2 = (t2 >> l$) / 4
+		}
+	}
+	else
+	{
+		# Limit between 2.4 and 3.
+		limit = 2.7 >> (l$ * 2)
+		print "limit: ", limit, "\n"
+
+		if (i >= limit)
+		{
+			t2 = (t2 >> l$) * 2
+		}
+		else
+		{
+			t2 = (t2 >> l$)
+		}
+	}
+	#t2 = 1
+	t3 = sqrt(5/(3*i))
+	good = (t1 < t2 && t2 < t3)
+
+	print t1, " < ", t2, " < ", t3, ": ", good, "\n\n"
+	if (!good) sqrt(-1)
+}
+
+halt
diff --git a/contrib/bc/scripts/sqrt_int_guess.bc b/contrib/bc/scripts/sqrt_int_guess.bc
new file mode 100644
index 000000000000..551a06eb2e6d
--- /dev/null
+++ b/contrib/bc/scripts/sqrt_int_guess.bc
@@ -0,0 +1,94 @@
+#! /usr/bin/bc -l
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (c) 2018-2023 Gavin D. Howard and contributors.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# * Redistributions of source code must retain the above copyright notice, this
+#   list of conditions and the following disclaimer.
+#
+# * Redistributions in binary form must reproduce the above copyright notice,
+#   this list of conditions and the following disclaimer in the documentation
+#   and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+# Adjust this number to try ranges above different powers of 10.
+max = 0
+
+n = (1 << max)
+
+# Uncomment this to test the high part of the ranges.
+#n += (1 - (1 >> 10))
+
+n
+
+# Loop from the start number to the next power of 10.
+for (i = n; i < (n$ << 1); i += 1)
+{
+	# This is the lower limit.
+	t1 = sqrt(1/(3*i))
+
+	l = length(i$)/2
+
+	print "i: ", i, "\n"
+	#print "l: ", l, "\n"
+
+	if (l$ != l)
+	{
+		# Limit between 2.4 and 3.
+		limit = 2.7 << (l$ * 2)
+		#print "limit: ", limit, "\n"
+
+		if (i >= limit)
+		{
+			t2 = 1/(i >> (l$)) * 2
+		}
+		else
+		{
+			t2 = 1/(i >> (l$))
+		}
+	}
+	else
+	{
+		# Limit between 3.8-ish and 4.8
+		limit = 4.3 << (l$ * 2 - 1)
+		#print "limit: ", limit, "\n"
+
+		if (i >= limit)
+		{
+			t2 = 1/(i >> (l$ - 1)) * 8
+		}
+		else
+		{
+			t2 = 1/(i >> (l$ - 1)) * 4
+		}
+	}
+
+	# This is the upper limit.
+	t3 = sqrt(5/(3*i))
+
+	# This is true when the guess is in between the limits.
+	good = (t1 < t2 && t2 < t3)
+
+	print t1, " < ", t2, " < ", t3, ": ", good, "\n"
+
+	# Error if we have a problem.
+	if (!good) sqrt(-1)
+}
+
+halt
diff --git a/contrib/bc/scripts/sqrt_random.bc b/contrib/bc/scripts/sqrt_random.bc
new file mode 100644
index 000000000000..ff08348f4977
--- /dev/null
+++ b/contrib/bc/scripts/sqrt_random.bc
@@ -0,0 +1,129 @@
+#! /usr/bin/bc
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (c) 2018-2023 Gavin D. Howard and contributors.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# * Redistributions of source code must retain the above copyright notice, this
+#   list of conditions and the following disclaimer.
+#
+# * Redistributions in binary form must reproduce the above copyright notice,
+#   this list of conditions and the following disclaimer in the documentation
+#   and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+scale = 0
+
+bits = rand()
+
+# This extracts a bit and takes it out of the original value.
+#
+# Here, I am getting a bit to say whether we should have a value that is less
+# than 1.
+bits = divmod(bits, 2, negpow[])
+
+# Get a bit that will say whether the value should be an exact square.
+bits = divmod(bits, 2, square[])
+
+# See below. This is to help bias toward small numbers.
+pow = 4
+
+# I want to bias toward small numbers, so let's give a 50 percent chance to
+# values below 16 or so.
+bits = divmod(bits, 2, small[])
+
+# Let's keep raising the power limit by 2^4 when the bit is zero.
+while (!small[0])
+{
+	pow += 4
+	bits = divmod(bits, 2, small[])
+}
+
+limit = 2^pow
+
+# Okay, this is the starting number.
+num = irand(limit) + 1
+
+# Figure out if we should have (more) fractional digits.
+bits = divmod(bits, 2, extra_digits[])
+
+if (square[0])
+{
+	# Okay, I lied. If we need a perfect square, square now.
+	num *= num
+
+	# If we need extra digits, we need to multiply by an even power of 10.
+	if (extra_digits[0])
+	{
+		extra = (irand(8) + 1) * 2
+	}
+	else
+	{
+		extra = 0
+	}
+
+	# If we need a number less than 1, just take the inverse, which will still
+	# be a perfect square.
+	if (negpow[0])
+	{
+		scale = length(num) + 5
+		num = 1/num
+		scale = 0
+
+		num >>= extra
+	}
+	else
+	{
+		num <<= extra
+	}
+}
+else
+{
+	# Get this for later.
+	l = length(num)
+
+	# If we need extra digits.
+	if (extra_digits[0])
+	{
+		# Add up to 32 decimal places.
+		num += frand(irand(32) + 1)
+	}
+
+	# If we need a value less than 1...
+	if (negpow[0])
+	{
+		# Move right until the number is
+		num >>= l
+	}
+}
+
+bits = divmod(bits, 2, zero_scale[])
+
+# Do we want a zero scale?
+if (zero_scale[0])
+{
+	print "scale = 0\n"
+}
+else
+{
+	print "scale = 20\n"
+}
+
+print "sqrt(", num, ")\n"
+
+halt
diff --git a/contrib/bc/scripts/sqrt_random.sh b/contrib/bc/scripts/sqrt_random.sh
new file mode 100755
index 000000000000..694c72003192
--- /dev/null
+++ b/contrib/bc/scripts/sqrt_random.sh
@@ -0,0 +1,77 @@
+#! /bin/sh
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (c) 2018-2023 Gavin D. Howard and contributors.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# * Redistributions of source code must retain the above copyright notice, this
+#   list of conditions and the following disclaimer.
+#
+# * Redistributions in binary form must reproduce the above copyright notice,
+#   this list of conditions and the following disclaimer in the documentation
+#   and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+scriptdir=$(dirname "$0")
+
+gnu=/usr/bin/bc
+gdh=/usr/local/bin/bc
+
+if [ "$#" -lt 1 ]; then
+	printf 'err: must provide path to new bc\n'
+	exit 1
+fi
+
+new="$1"
+shift
+
+unset BC_LINE_LENGTH && unset BC_ENV_ARGS
+
+gdh_fail_file="sqrt_fails.bc"
+new_fail_file="new_sqrt_fails.bc"
+
+rm -rf "$gdh_fail_file"
+rm -rf "$new_fail_file"
+
+while [ true ]; do
+
+	tst=$("$gdh" -l "$scriptdir/sqrt_random.bc")
+	err=$?
+
+	if [ "$err" -ne 0 ]; then
+		printf 'err: failed to create test\n'
+		exit 2
+	fi
+
+	good=$(printf '%s\n' "$tst" | "$gnu" -l)
+
+	gdh_out=$(printf '%s\n' "$tst" | "$gdh" -l)
+	new_out=$(printf '%s\n' "$tst" | "$new" -l)
+
+	gdh_good=$(printf '%s == %s\n' "$good" "$gdh_out" | "$gnu")
+	new_good=$(printf '%s == %s\n' "$good" "$new_out" | "$gnu")
+
+	if [ "$gdh_good" -eq 0 ]; then
+		printf '%s\n' "$tst" >> "$gdh_fail_file"
+	fi
+
+	if [ "$new_good" -eq 0 ]; then
+		printf '%s\n' "$tst" >> "$new_fail_file"
+	fi
+
+done
diff --git a/contrib/bc/src/num.c b/contrib/bc/src/num.c
index e45aa62ddd0f..ac0f828008f8 100644
--- a/contrib/bc/src/num.c
+++ b/contrib/bc/src/num.c
@@ -3207,12 +3207,30 @@ bc_num_printNum(BcNum* restrict n, BcBigDig base, size_t len,
 		assert(ptr != NULL);
 
 		// While the first three arguments should be self-explanatory, the last
-		// needs explaining. I don't want to print a newline when the last digit
-		// to be printed could take the place of the backslash rather than being
-		// pushed, as a single character, to the next line. That's what that
-		// last argument does for bc.
+		// needs explaining. I don't want to print a backslash+newline when the
+		// last digit to be printed could take the place of the backslash rather
+		// than being pushed, as a single character, to the next line. That's
+		// what that last argument does for bc.
+		//
+		// First, it needs to check if newlines are completely disabled. If they
+		// are not disabled, it needs to check the next part.
+		//
+		// If the number has a scale, then because we are printing just the
+		// integer part, there will be at least two more characters (a radix
+		// point plus at least one digit). So if there is a scale, a backslash
+		// is necessary.
+		//
+		// Finally, the last condition checks to see if we are at the end of the
+		// stack. If we are *not* (i.e., the index is not one less than the
+		// stack length), then a backslash is necessary because there is at
+		// least one more character for at least one more digit). Otherwise, if
+		// the index is equal to one less than the stack length, we want to
+		// disable backslash printing.
+		//
+		// The function that prints bases 17 and above will take care of not
+		// printing a backslash in the right case.
 		print(*ptr, len, false,
-		      !newline || (n->scale != 0 || i == stack.len - 1));
+		      !newline || (n->scale != 0 || i < stack.len - 1));
 	}
 
 	// We are done if there is no fractional part.
@@ -4091,13 +4109,14 @@ bc_num_sqrt(BcNum* restrict a, BcNum* restrict b, size_t scale)
 
 	// Square root needs half of the length of the parameter.
 	req = bc_vm_growSize(BC_MAX(rdx, BC_NUM_RDX_VAL(a)), len >> 1);
+	req = bc_vm_growSize(req, 1);
 
 	BC_SIG_LOCK;
 
 	// Unlike the binary operators, this function is the only single parameter
 	// function and is expected to initialize the result. This means that it
 	// expects that b is *NOT* preallocated. We allocate it here.
-	bc_num_init(b, bc_vm_growSize(req, 1));
+	bc_num_init(b, req);
 
 	BC_SIG_UNLOCK;
 
@@ -4130,13 +4149,12 @@ bc_num_sqrt(BcNum* restrict a, BcNum* restrict b, size_t scale)
 	bc_num_init(&num2, len);
 	bc_num_setup(&half, half_digs, sizeof(half_digs) / sizeof(BcDig));
 
-	// There is a division by two in the formula. We setup a number that's 1/2
+	// There is a division by two in the formula. We set up a number that's 1/2
 	// so that we can use multiplication instead of heavy division.
-	bc_num_one(&half);
+	bc_num_setToZero(&half, 1);
 	half.num[0] = BC_BASE_POW / 2;
 	half.len = 1;
 	BC_NUM_RDX_SET_NP(half, 1);
-	half.scale = 1;
 
 	bc_num_init(&f, len);
 	bc_num_init(&fprime, len);
@@ -4156,8 +4174,9 @@ bc_num_sqrt(BcNum* restrict a, BcNum* restrict b, size_t scale)
 	pow = bc_num_intDigits(a);
 
 	// The code in this if statement calculates the initial estimate. First, if
-	// a is less than 0, then 0 is a good estimate. Otherwise, we want something
-	// in the same ballpark. That ballpark is pow.
+	// a is less than 1, then 0 is a good estimate. Otherwise, we want something
+	// in the same ballpark. That ballpark is half of pow because the result
+	// will have half the digits.
 	if (pow)
 	{
 		// An odd number is served by starting with 2^((pow-1)/2), and an even
diff --git a/contrib/bc/src/program.c b/contrib/bc/src/program.c
index 2f26589166e3..c9d268dfde82 100644
--- a/contrib/bc/src/program.c
+++ b/contrib/bc/src/program.c
@@ -3780,7 +3780,7 @@ bc_program_printStr(const BcProgram* p, const char* restrict code,
 	size_t idx = bc_program_index(code, bgn);
 	char* s;
 
-	s = *((char**) bc_vec_item(p->strs, idx));
+	s = *((char**) bc_vec_item(&p->strs, idx));
 
 	bc_vm_printf(" (\"%s\") ", s);
 }
@@ -3803,7 +3803,7 @@ bc_program_printInst(const BcProgram* p, const char* restrict code,
 	else if (inst == BC_INST_NUM)
 	{
 		size_t idx = bc_program_index(code, bgn);
-		BcConst* c = bc_vec_item(p->consts, idx);
+		BcConst* c = bc_vec_item(&p->consts, idx);
 		bc_vm_printf("(%s)", c->val);
 	}
 	else if (inst == BC_INST_CALL ||
diff --git a/contrib/bc/tests/bc/scripts/all.txt b/contrib/bc/tests/bc/scripts/all.txt
index 0008d70193c6..7b49f7c4e77a 100644
--- a/contrib/bc/tests/bc/scripts/all.txt
+++ b/contrib/bc/tests/bc/scripts/all.txt
@@ -3,6 +3,7 @@ divide.bc
 subtract.bc
 add.bc
 print.bc
+print2.bc
 parse.bc
 root.bc
 array.bc
diff --git a/contrib/bc/tests/bc/scripts/print2.bc b/contrib/bc/tests/bc/scripts/print2.bc
new file mode 100644
index 000000000000..5f3466929f77
--- /dev/null
+++ b/contrib/bc/tests/bc/scripts/print2.bc
@@ -0,0 +1,63 @@
+#! /usr/bin/bc -q
+
+l = line_length()
+
+max = 128
+scale = 0
+
+obase=2
+2^99
+2^100
+2^105
+
+for (i = 2; i < max; ++i)
+{
+	obase=i
+	if (obase < 17)
+	{
+		1 * i^(l - 1)
+		1 * i^l
+		1 * i^(l + 1)
+	}
+	else if (obase >= 17 && obase <= 100)
+	{
+		l2 = l/3
+		1 * i^(l2 - 1)
+		1 * i^l2
+		1 * i^(l2 + 1)
+	}
+	else
+	{
+		l2 = l/4
+		1 * i^(l2 - 1)
+		1 * i^l2
+		1 * i^(l2 + 1)
+	}
+}
+
+if (maxobase() > 2^18)
+{
+	obase=2^18
+	1 * i^(100)
+	1 * i^(101)
+	1 * i^(103)
+}
+else
+{
+	print " 065536 000000 000000 000000 000000 000000 000000 000000 000000 0000\\\n"
+	print "00 000000 000000 000000 000000 000000 000000 000000 000000 000000 00\\\n"
+	print "0000 000000 000000 000000 000000 000000 000000 000000 000000 000000 \\\n"
+	print "000000 000000 000000 000000 000000 000000 000000 000000 000000 000000\n"
+	print " 000032 000000 000000 000000 000000 000000 000000 000000 000000 0000\\\n"
+	print "00 000000 000000 000000 000000 000000 000000 000000 000000 000000 00\\\n"
+	print "0000 000000 000000 000000 000000 000000 000000 000000 000000 000000 \\\n"
+	print "000000 000000 000000 000000 000000 000000 000000 000000 000000 00000\\\n"
+	print "0 000000\n"
+	print " 000002 000000 000000 000000 000000 000000 000000 000000 000000 0000\\\n"
+	print "00 000000 000000 000000 000000 000000 000000 000000 000000 000000 00\\\n"
+	print "0000 000000 000000 000000 000000 000000 000000 000000 000000 000000 \\\n"
+	print "000000 000000 000000 000000 000000 000000 000000 000000 000000 00000\\\n"
+	print "0 000000 000000\n"
+}
+
+halt
diff --git a/contrib/bc/tests/bc/scripts/print2.txt b/contrib/bc/tests/bc/scripts/print2.txt
new file mode 100644
index 000000000000..208f0ed2e479
--- /dev/null
+++ b/contrib/bc/tests/bc/scripts/print2.txt
@@ -0,0 +1,650 @@
+10000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000
+10000000000000000000000000000000000000000000000000000000000000000000\
+000000000000000000000000000000000
+10000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000
+100000000000000000000000000000000000000000000000000000000000000000000
+10000000000000000000000000000000000000000000000000000000000000000000\
+00
+10000000000000000000000000000000000000000000000000000000000000000000\
+000
+100000000000000000000000000000000000000000000000000000000000000000000
+10000000000000000000000000000000000000000000000000000000000000000000\
+00
+10000000000000000000000000000000000000000000000000000000000000000000\
+000
+100000000000000000000000000000000000000000000000000000000000000000000
+10000000000000000000000000000000000000000000000000000000000000000000\
+00
+10000000000000000000000000000000000000000000000000000000000000000000\
+000
+100000000000000000000000000000000000000000000000000000000000000000000
+10000000000000000000000000000000000000000000000000000000000000000000\
+00
+10000000000000000000000000000000000000000000000000000000000000000000\
+000
+100000000000000000000000000000000000000000000000000000000000000000000
+10000000000000000000000000000000000000000000000000000000000000000000\
+00
+10000000000000000000000000000000000000000000000000000000000000000000\
+000
+100000000000000000000000000000000000000000000000000000000000000000000
+10000000000000000000000000000000000000000000000000000000000000000000\
+00
+10000000000000000000000000000000000000000000000000000000000000000000\
+000
+100000000000000000000000000000000000000000000000000000000000000000000
+10000000000000000000000000000000000000000000000000000000000000000000\
+00
+10000000000000000000000000000000000000000000000000000000000000000000\
+000
+100000000000000000000000000000000000000000000000000000000000000000000
+10000000000000000000000000000000000000000000000000000000000000000000\
+00
+10000000000000000000000000000000000000000000000000000000000000000000\
+000
+100000000000000000000000000000000000000000000000000000000000000000000
+10000000000000000000000000000000000000000000000000000000000000000000\
+00
+10000000000000000000000000000000000000000000000000000000000000000000\
+000
+100000000000000000000000000000000000000000000000000000000000000000000
+10000000000000000000000000000000000000000000000000000000000000000000\
+00
+10000000000000000000000000000000000000000000000000000000000000000000\
+000
+100000000000000000000000000000000000000000000000000000000000000000000
+10000000000000000000000000000000000000000000000000000000000000000000\
+00
+10000000000000000000000000000000000000000000000000000000000000000000\
+000
+100000000000000000000000000000000000000000000000000000000000000000000
+10000000000000000000000000000000000000000000000000000000000000000000\
+00
+10000000000000000000000000000000000000000000000000000000000000000000\
+000
+100000000000000000000000000000000000000000000000000000000000000000000
+10000000000000000000000000000000000000000000000000000000000000000000\
+00
+10000000000000000000000000000000000000000000000000000000000000000000\
+000
+100000000000000000000000000000000000000000000000000000000000000000000
+10000000000000000000000000000000000000000000000000000000000000000000\
+00
+10000000000000000000000000000000000000000000000000000000000000000000\
+000
+100000000000000000000000000000000000000000000000000000000000000000000
+10000000000000000000000000000000000000000000000000000000000000000000\
+00
+10000000000000000000000000000000000000000000000000000000000000000000\
+000
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0\
+0 00
*** 532 LINES SKIPPED ***



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202401101638.40AGcHGO069314>