From 8c48f4c5377ddc3dc55388f181f23111145f7099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20E=C3=9Fer?= Date: Sun, 30 Apr 2023 19:53:26 +0200 Subject: [PATCH] contrib/bc: import version 6.5.0 This release that fixes an infinite loop bug in the (non-standard) extended math library functions root() and cbrt(), fixes a bug with BC_LINE_LENGTH=0, and adds the fib() function to the extended math library to calculate Fibonacci numbers. (cherry picked from commit 438a1101dc1f687928cdbe02cd7817a88a24f42f) MFC after: 3 days --- contrib/bc/NEWS.md | 6 + contrib/bc/gen/lib2.bc | 24 ++- contrib/bc/include/version.h | 2 +- contrib/bc/src/vm.c | 8 +- contrib/bc/tests/bc/all.txt | 1 + contrib/bc/tests/bc/fib.txt | 31 ++++ contrib/bc/tests/bc/fib_results.txt | 31 ++++ contrib/bc/tests/bc/scripts/all.txt | 1 + contrib/bc/tests/bc/scripts/cbrt.txt | 100 +++++++++++ contrib/bc/tests/bc/scripts/root.bc | 19 ++ contrib/bc/tests/bc/scripts/root.txt | 255 +++++++++++++++++++++++++++ contrib/bc/tests/extra_required.txt | 1 + contrib/bc/tests/script.sh | 2 +- 13 files changed, 473 insertions(+), 8 deletions(-) create mode 100644 contrib/bc/tests/bc/fib.txt create mode 100644 contrib/bc/tests/bc/fib_results.txt create mode 100644 contrib/bc/tests/bc/scripts/cbrt.txt create mode 100644 contrib/bc/tests/bc/scripts/root.bc create mode 100644 contrib/bc/tests/bc/scripts/root.txt diff --git a/contrib/bc/NEWS.md b/contrib/bc/NEWS.md index 6dff6822fb16..44b17b060f5c 100644 --- a/contrib/bc/NEWS.md +++ b/contrib/bc/NEWS.md @@ -1,5 +1,11 @@ # News +## 6.5.0 + +This is a production release that fixes an infinite loop bug in `root()` and +`cbrt()`, fixes a bug with `BC_LINE_LENGTH=0`, and adds the `fib()` function to +the extended math library to calculate Fibonacci numbers. + ## 6.4.0 This is a production release that fixes a `read()`/`?` bug and adds features to diff --git a/contrib/bc/gen/lib2.bc b/contrib/bc/gen/lib2.bc index 2811430d534e..ba3f76b1803a 100644 --- a/contrib/bc/gen/lib2.bc +++ b/contrib/bc/gen/lib2.bc @@ -93,6 +93,18 @@ define comb(n,r){ scale=s return f } +define fib(n){ + auto i,t,p,r + if(!n)return 0 + n=abs(n)$ + t=1 + for (i=1;i= UINT16_MAX) len = BC_NUM_PRINT_WIDTH; + len = (size_t) strtol(lenv, NULL, 10); + if (len != 0) + { + len -= 1; + if (len < 2 || len >= UINT16_MAX) len = BC_NUM_PRINT_WIDTH; + } } // Set the default. else len = BC_NUM_PRINT_WIDTH; diff --git a/contrib/bc/tests/bc/all.txt b/contrib/bc/tests/bc/all.txt index af5eaaa42fb7..3d0ea05ba7c0 100644 --- a/contrib/bc/tests/bc/all.txt +++ b/contrib/bc/tests/bc/all.txt @@ -34,6 +34,7 @@ arctangent sine cosine bessel +fib arrays misc misc1 diff --git a/contrib/bc/tests/bc/fib.txt b/contrib/bc/tests/bc/fib.txt new file mode 100644 index 000000000000..2fa2eea143ed --- /dev/null +++ b/contrib/bc/tests/bc/fib.txt @@ -0,0 +1,31 @@ +fib(0) +fib(1) +fib(2) +fib(3) +fib(4) +fib(5) +fib(6) +fib(7) +fib(8) +fib(9) +fib(10) +fib(11) +fib(12) +fib(13) +fib(14) +fib(15) +fib(16) +fib(17) +fib(18) +fib(19) +fib(20) +fib(21) +fib(22) +fib(23) +fib(24) +fib(25) +fib(26) +fib(27) +fib(28) +fib(29) +fib(30) diff --git a/contrib/bc/tests/bc/fib_results.txt b/contrib/bc/tests/bc/fib_results.txt new file mode 100644 index 000000000000..1837f6b7414f --- /dev/null +++ b/contrib/bc/tests/bc/fib_results.txt @@ -0,0 +1,31 @@ +0 +1 +1 +2 +3 +5 +8 +13 +21 +34 +55 +89 +144 +233 +377 +610 +987 +1597 +2584 +4181 +6765 +10946 +17711 +28657 +46368 +75025 +121393 +196418 +317811 +514229 +832040 diff --git a/contrib/bc/tests/bc/scripts/all.txt b/contrib/bc/tests/bc/scripts/all.txt index e2d2aa320c6f..a226bed54234 100644 --- a/contrib/bc/tests/bc/scripts/all.txt +++ b/contrib/bc/tests/bc/scripts/all.txt @@ -4,6 +4,7 @@ subtract.bc add.bc print.bc parse.bc +root.bc array.bc array2.bc atan.bc diff --git a/contrib/bc/tests/bc/scripts/cbrt.txt b/contrib/bc/tests/bc/scripts/cbrt.txt new file mode 100644 index 000000000000..bae7f3af0578 --- /dev/null +++ b/contrib/bc/tests/bc/scripts/cbrt.txt @@ -0,0 +1,100 @@ +.464158883361277889241007635091 +.215443469003188372175929356651 +.100000000000000000000000000000 +.046415888336127788924100763509 +.021544346900318837217592935665 +.010000000000000000000000000000 +.004641588833612778892410076350 +.002154434690031883721759293566 +.001000000000000000000000000000 +.000464158883361277889241007635 +.000215443469003188372175929356 +.000100000000000000000000000000 +.000046415888336127788924100763 +.000021544346900318837217592935 +.000010000000000000000000000000 +.000004641588833612778892410076 +.000002154434690031883721759293 +.000001000000000000000000000000 +.000000464158883361277889241007 +.000000215443469003188372175929 +.000000100000000000000000000000 +.000000046415888336127788924100 +.000000021544346900318837217592 +.000000010000000000000000000000 +.000000004641588833612778892410 +.000000002154434690031883721759 +.000000001000000000000000000000 +.000000000464158883361277889241 +.000000000215443469003188372175 +.000000000100000000000000000000 +.000000000046415888336127788924 +.000000000021544346900318837217 +.000000000010000000000000000000 +.000000000004641588833612778892 +.000000000002154434690031883721 +.000000000001000000000000000000 +.000000000000464158883361277889 +.000000000000215443469003188372 +.000000000000100000000000000000 +.000000000000046415888336127788 +.000000000000021544346900318837 +.000000000000010000000000000000 +.000000000000004641588833612778 +.000000000000002154434690031883 +.000000000000001000000000000000 +.000000000000000464158883361277 +.000000000000000215443469003188 +.000000000000000100000000000000 +.000000000000000046415888336127 +.000000000000000021544346900318 +.000000000000000010000000000000 +.000000000000000004641588833612 +.000000000000000002154434690031 +.000000000000000001000000000000 +.000000000000000000464158883361 +.000000000000000000215443469003 +.000000000000000000100000000000 +.000000000000000000046415888336 +.000000000000000000021544346900 +.000000000000000000010000000000 +.000000000000000000004641588833 +.000000000000000000002154434690 +.000000000000000000001000000000 +.000000000000000000000464158883 +.000000000000000000000215443469 +.000000000000000000000100000000 +.000000000000000000000046415888 +.000000000000000000000021544346 +.000000000000000000000010000000 +.000000000000000000000004641588 +.000000000000000000000002154434 +.000000000000000000000001000000 +.000000000000000000000000464158 +.000000000000000000000000215443 +.000000000000000000000000100000 +.000000000000000000000000046415 +.000000000000000000000000021544 +.000000000000000000000000010000 +.000000000000000000000000004641 +.000000000000000000000000002154 +.000000000000000000000000001000 +.000000000000000000000000000464 +.000000000000000000000000000215 +.000000000000000000000000000100 +.000000000000000000000000000046 +.000000000000000000000000000021 +.000000000000000000000000000010 +.000000000000000000000000000004 +.000000000000000000000000000002 +.000000000000000000000000000001 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 diff --git a/contrib/bc/tests/bc/scripts/root.bc b/contrib/bc/tests/bc/scripts/root.bc new file mode 100644 index 000000000000..95210fe290e6 --- /dev/null +++ b/contrib/bc/tests/bc/scripts/root.bc @@ -0,0 +1,19 @@ +scale = 30 + +s = 1 >> 1 + +for (i = 0; i < 100; ++i) +{ + cbrt(s) + s >>= 1 +} + +s = 1 >> 1 + +for (i = 0; i < 155; ++i) +{ + root(s, 5) + s >>= 1 +} + +halt diff --git a/contrib/bc/tests/bc/scripts/root.txt b/contrib/bc/tests/bc/scripts/root.txt new file mode 100644 index 000000000000..b720eb5de75f --- /dev/null +++ b/contrib/bc/tests/bc/scripts/root.txt @@ -0,0 +1,255 @@ +.464158883361277889241007635091 +.215443469003188372175929356651 +.100000000000000000000000000000 +.046415888336127788924100763509 +.021544346900318837217592935665 +.010000000000000000000000000000 +.004641588833612778892410076350 +.002154434690031883721759293566 +.001000000000000000000000000000 +.000464158883361277889241007635 +.000215443469003188372175929356 +.000100000000000000000000000000 +.000046415888336127788924100763 +.000021544346900318837217592935 +.000010000000000000000000000000 +.000004641588833612778892410076 +.000002154434690031883721759293 +.000001000000000000000000000000 +.000000464158883361277889241007 +.000000215443469003188372175929 +.000000100000000000000000000000 +.000000046415888336127788924100 +.000000021544346900318837217592 +.000000010000000000000000000000 +.000000004641588833612778892410 +.000000002154434690031883721759 +.000000001000000000000000000000 +.000000000464158883361277889241 +.000000000215443469003188372175 +.000000000100000000000000000000 +.000000000046415888336127788924 +.000000000021544346900318837217 +.000000000010000000000000000000 +.000000000004641588833612778892 +.000000000002154434690031883721 +.000000000001000000000000000000 +.000000000000464158883361277889 +.000000000000215443469003188372 +.000000000000100000000000000000 +.000000000000046415888336127788 +.000000000000021544346900318837 +.000000000000010000000000000000 +.000000000000004641588833612778 +.000000000000002154434690031883 +.000000000000001000000000000000 +.000000000000000464158883361277 +.000000000000000215443469003188 +.000000000000000100000000000000 +.000000000000000046415888336127 +.000000000000000021544346900318 +.000000000000000010000000000000 +.000000000000000004641588833612 +.000000000000000002154434690031 +.000000000000000001000000000000 +.000000000000000000464158883361 +.000000000000000000215443469003 +.000000000000000000100000000000 +.000000000000000000046415888336 +.000000000000000000021544346900 +.000000000000000000010000000000 +.000000000000000000004641588833 +.000000000000000000002154434690 +.000000000000000000001000000000 +.000000000000000000000464158883 +.000000000000000000000215443469 +.000000000000000000000100000000 +.000000000000000000000046415888 +.000000000000000000000021544346 +.000000000000000000000010000000 +.000000000000000000000004641588 +.000000000000000000000002154434 +.000000000000000000000001000000 +.000000000000000000000000464158 +.000000000000000000000000215443 +.000000000000000000000000100000 +.000000000000000000000000046415 +.000000000000000000000000021544 +.000000000000000000000000010000 +.000000000000000000000000004641 +.000000000000000000000000002154 +.000000000000000000000000001000 +.000000000000000000000000000464 +.000000000000000000000000000215 +.000000000000000000000000000100 +.000000000000000000000000000046 +.000000000000000000000000000021 +.000000000000000000000000000010 +.000000000000000000000000000004 +.000000000000000000000000000002 +.000000000000000000000000000001 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +.630957344480193249434360136622 +.398107170553497250770252305087 +.251188643150958011108503206779 +.158489319246111348520210137339 +.100000000000000000000000000000 +.063095734448019324943436013662 +.039810717055349725077025230508 +.025118864315095801110850320677 +.015848931924611134852021013733 +.010000000000000000000000000000 +.006309573444801932494343601366 +.003981071705534972507702523050 +.002511886431509580111085032067 +.001584893192461113485202101373 +.001000000000000000000000000000 +.000630957344480193249434360136 +.000398107170553497250770252305 +.000251188643150958011108503206 +.000158489319246111348520210137 +.000100000000000000000000000000 +.000063095734448019324943436013 +.000039810717055349725077025230 +.000025118864315095801110850320 +.000015848931924611134852021013 +.000010000000000000000000000000 +.000006309573444801932494343601 +.000003981071705534972507702523 +.000002511886431509580111085032 +.000001584893192461113485202101 +.000001000000000000000000000000 +.000000630957344480193249434360 +.000000398107170553497250770252 +.000000251188643150958011108503 +.000000158489319246111348520210 +.000000100000000000000000000000 +.000000063095734448019324943436 +.000000039810717055349725077025 +.000000025118864315095801110850 +.000000015848931924611134852021 +.000000010000000000000000000000 +.000000006309573444801932494343 +.000000003981071705534972507702 +.000000002511886431509580111085 +.000000001584893192461113485202 +.000000001000000000000000000000 +.000000000630957344480193249434 +.000000000398107170553497250770 +.000000000251188643150958011108 +.000000000158489319246111348520 +.000000000100000000000000000000 +.000000000063095734448019324943 +.000000000039810717055349725077 +.000000000025118864315095801110 +.000000000015848931924611134852 +.000000000010000000000000000000 +.000000000006309573444801932494 +.000000000003981071705534972507 +.000000000002511886431509580111 +.000000000001584893192461113485 +.000000000001000000000000000000 +.000000000000630957344480193249 +.000000000000398107170553497250 +.000000000000251188643150958011 +.000000000000158489319246111348 +.000000000000100000000000000000 +.000000000000063095734448019324 +.000000000000039810717055349725 +.000000000000025118864315095801 +.000000000000015848931924611134 +.000000000000010000000000000000 +.000000000000006309573444801932 +.000000000000003981071705534972 +.000000000000002511886431509580 +.000000000000001584893192461113 +.000000000000001000000000000000 +.000000000000000630957344480193 +.000000000000000398107170553497 +.000000000000000251188643150958 +.000000000000000158489319246111 +.000000000000000100000000000000 +.000000000000000063095734448019 +.000000000000000039810717055349 +.000000000000000025118864315095 +.000000000000000015848931924611 +.000000000000000010000000000000 +.000000000000000006309573444801 +.000000000000000003981071705534 +.000000000000000002511886431509 +.000000000000000001584893192461 +.000000000000000001000000000000 +.000000000000000000630957344480 +.000000000000000000398107170553 +.000000000000000000251188643150 +.000000000000000000158489319246 +.000000000000000000100000000000 +.000000000000000000063095734448 +.000000000000000000039810717055 +.000000000000000000025118864315 +.000000000000000000015848931924 +.000000000000000000010000000000 +.000000000000000000006309573444 +.000000000000000000003981071705 +.000000000000000000002511886431 +.000000000000000000001584893192 +.000000000000000000001000000000 +.000000000000000000000630957344 +.000000000000000000000398107170 +.000000000000000000000251188643 +.000000000000000000000158489319 +.000000000000000000000100000000 +.000000000000000000000063095734 +.000000000000000000000039810717 +.000000000000000000000025118864 +.000000000000000000000015848931 +.000000000000000000000010000000 +.000000000000000000000006309573 +.000000000000000000000003981071 +.000000000000000000000002511886 +.000000000000000000000001584893 +.000000000000000000000001000000 +.000000000000000000000000630957 +.000000000000000000000000398107 +.000000000000000000000000251188 +.000000000000000000000000158489 +.000000000000000000000000100000 +.000000000000000000000000063095 +.000000000000000000000000039810 +.000000000000000000000000025118 +.000000000000000000000000015848 +.000000000000000000000000010000 +.000000000000000000000000006309 +.000000000000000000000000003981 +.000000000000000000000000002511 +.000000000000000000000000001584 +.000000000000000000000000001000 +.000000000000000000000000000630 +.000000000000000000000000000398 +.000000000000000000000000000251 +.000000000000000000000000000158 +.000000000000000000000000000100 +.000000000000000000000000000063 +.000000000000000000000000000039 +.000000000000000000000000000025 +.000000000000000000000000000015 +.000000000000000000000000000010 +.000000000000000000000000000006 +.000000000000000000000000000003 +.000000000000000000000000000002 +.000000000000000000000000000001 +.000000000000000000000000000001 +0 +0 +0 +0 +0 diff --git a/contrib/bc/tests/extra_required.txt b/contrib/bc/tests/extra_required.txt index e36d95a1305b..c498802ffaea 100644 --- a/contrib/bc/tests/extra_required.txt +++ b/contrib/bc/tests/extra_required.txt @@ -1,5 +1,6 @@ engineering lib2 +fib places rand scientific diff --git a/contrib/bc/tests/script.sh b/contrib/bc/tests/script.sh index 438af17c79c4..fef0c5290615 100755 --- a/contrib/bc/tests/script.sh +++ b/contrib/bc/tests/script.sh @@ -132,7 +132,7 @@ fi # Skip the tests that require extra math if we don't have it. if [ "$run_extra_tests" -eq 0 ]; then - if [ "$f" = "rand.bc" ]; then + if [ "$f" = "rand.bc" ] || [ "$f" = "root.bc" ]; then printf 'Skipping %s script: %s\n' "$d" "$f" exit 0 fi