xref: /freebsd/contrib/bc/scripts/sqrt_random.sh (revision a970610a3af63b3f4df5b69d91c6b4093a00ed8f)
1f4fbc49dSStefan Eßer#! /bin/sh
2f4fbc49dSStefan Eßer#
3f4fbc49dSStefan Eßer# SPDX-License-Identifier: BSD-2-Clause
4f4fbc49dSStefan Eßer#
5*a970610aSStefan Eßer# Copyright (c) 2018-2024 Gavin D. Howard and contributors.
6f4fbc49dSStefan Eßer#
7f4fbc49dSStefan Eßer# Redistribution and use in source and binary forms, with or without
8f4fbc49dSStefan Eßer# modification, are permitted provided that the following conditions are met:
9f4fbc49dSStefan Eßer#
10f4fbc49dSStefan Eßer# * Redistributions of source code must retain the above copyright notice, this
11f4fbc49dSStefan Eßer#   list of conditions and the following disclaimer.
12f4fbc49dSStefan Eßer#
13f4fbc49dSStefan Eßer# * Redistributions in binary form must reproduce the above copyright notice,
14f4fbc49dSStefan Eßer#   this list of conditions and the following disclaimer in the documentation
15f4fbc49dSStefan Eßer#   and/or other materials provided with the distribution.
16f4fbc49dSStefan Eßer#
17f4fbc49dSStefan Eßer# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18f4fbc49dSStefan Eßer# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19f4fbc49dSStefan Eßer# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20f4fbc49dSStefan Eßer# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21f4fbc49dSStefan Eßer# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22f4fbc49dSStefan Eßer# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23f4fbc49dSStefan Eßer# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24f4fbc49dSStefan Eßer# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25f4fbc49dSStefan Eßer# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26f4fbc49dSStefan Eßer# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27f4fbc49dSStefan Eßer# POSSIBILITY OF SUCH DAMAGE.
28f4fbc49dSStefan Eßer#
29f4fbc49dSStefan Eßer
30f4fbc49dSStefan Eßerscriptdir=$(dirname "$0")
31f4fbc49dSStefan Eßer
32f4fbc49dSStefan Eßergnu=/usr/bin/bc
33f4fbc49dSStefan Eßergdh=/usr/local/bin/bc
34f4fbc49dSStefan Eßer
35f4fbc49dSStefan Eßerif [ "$#" -lt 1 ]; then
36f4fbc49dSStefan Eßer	printf 'err: must provide path to new bc\n'
37f4fbc49dSStefan Eßer	exit 1
38f4fbc49dSStefan Eßerfi
39f4fbc49dSStefan Eßer
40f4fbc49dSStefan Eßernew="$1"
41f4fbc49dSStefan Eßershift
42f4fbc49dSStefan Eßer
43f4fbc49dSStefan Eßerunset BC_LINE_LENGTH && unset BC_ENV_ARGS
44f4fbc49dSStefan Eßer
45f4fbc49dSStefan Eßergdh_fail_file="sqrt_fails.bc"
46f4fbc49dSStefan Eßernew_fail_file="new_sqrt_fails.bc"
47f4fbc49dSStefan Eßer
48f4fbc49dSStefan Eßerrm -rf "$gdh_fail_file"
49f4fbc49dSStefan Eßerrm -rf "$new_fail_file"
50f4fbc49dSStefan Eßer
51f4fbc49dSStefan Eßerwhile [ true ]; do
52f4fbc49dSStefan Eßer
53f4fbc49dSStefan Eßer	tst=$("$gdh" -l "$scriptdir/sqrt_random.bc")
54f4fbc49dSStefan Eßer	err=$?
55f4fbc49dSStefan Eßer
56f4fbc49dSStefan Eßer	if [ "$err" -ne 0 ]; then
57f4fbc49dSStefan Eßer		printf 'err: failed to create test\n'
58f4fbc49dSStefan Eßer		exit 2
59f4fbc49dSStefan Eßer	fi
60f4fbc49dSStefan Eßer
61f4fbc49dSStefan Eßer	good=$(printf '%s\n' "$tst" | "$gnu" -l)
62f4fbc49dSStefan Eßer
63f4fbc49dSStefan Eßer	gdh_out=$(printf '%s\n' "$tst" | "$gdh" -l)
64f4fbc49dSStefan Eßer	new_out=$(printf '%s\n' "$tst" | "$new" -l)
65f4fbc49dSStefan Eßer
66f4fbc49dSStefan Eßer	gdh_good=$(printf '%s == %s\n' "$good" "$gdh_out" | "$gnu")
67f4fbc49dSStefan Eßer	new_good=$(printf '%s == %s\n' "$good" "$new_out" | "$gnu")
68f4fbc49dSStefan Eßer
69f4fbc49dSStefan Eßer	if [ "$gdh_good" -eq 0 ]; then
70f4fbc49dSStefan Eßer		printf '%s\n' "$tst" >> "$gdh_fail_file"
71f4fbc49dSStefan Eßer	fi
72f4fbc49dSStefan Eßer
73f4fbc49dSStefan Eßer	if [ "$new_good" -eq 0 ]; then
74f4fbc49dSStefan Eßer		printf '%s\n' "$tst" >> "$new_fail_file"
75f4fbc49dSStefan Eßer	fi
76f4fbc49dSStefan Eßer
77f4fbc49dSStefan Eßerdone
78