diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/ChangeLog | 6 | ||||
-rw-r--r-- | test/Makefile.am | 9 | ||||
-rw-r--r-- | test/Makefile.in | 9 | ||||
-rw-r--r-- | test/mpfrsqrt.awk | 82 | ||||
-rw-r--r-- | test/mpfrsqrt.ok | 2 |
5 files changed, 106 insertions, 2 deletions
diff --git a/test/ChangeLog b/test/ChangeLog index 4f72280b..afbccf5f 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,9 @@ +2014-08-05 Arnold D. Robbins <arnold@skeeve.com> + + * Makefile.am (mpfrsqrt): New test. + * mpfrsqrt.awk, mpfrsqrt.ok: New files. + Test from Katie Wasserman <katie@wass.net>. + 2014-07-25 Arnold D. Robbins <arnold@skeeve.com> * printhuge.awk: Add a newline to output. diff --git a/test/Makefile.am b/test/Makefile.am index c822163a..8349a73e 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -533,6 +533,8 @@ EXTRA_DIST = \ mpfrrnd.ok \ mpfrsort.awk \ mpfrsort.ok \ + mpfrsqrt.awk \ + mpfrsqrt.ok \ mtchi18n.awk \ mtchi18n.in \ mtchi18n.ok \ @@ -1023,7 +1025,7 @@ INET_TESTS = inetdayu inetdayt inetechu inetecht MACHINE_TESTS = double1 double2 fmtspcl intformat MPFR_TESTS = mpfrnr mpfrnegzero mpfrrnd mpfrieee mpfrexprange \ - mpfrsort mpfrbigint + mpfrsort mpfrsqrt mpfrbigint LOCALE_CHARSET_TESTS = \ asort asorti backbigs1 backsmalls1 backsmalls2 \ @@ -1745,6 +1747,11 @@ mpfrbigint: @$(AWK) -M -f "$(srcdir)"/$@.awk > _$@ 2>&1 @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +mpfrsqrt: + @echo $@ + @$(AWK) -M -f "$(srcdir)"/$@.awk > _$@ 2>&1 + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + jarebug:: @echo $@ @"$(srcdir)"/$@.sh "$(AWKPROG)" "$(srcdir)"/$@.awk "$(srcdir)"/$@.in "_$@" diff --git a/test/Makefile.in b/test/Makefile.in index 1660ab8f..e8fd8844 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -779,6 +779,8 @@ EXTRA_DIST = \ mpfrrnd.ok \ mpfrsort.awk \ mpfrsort.ok \ + mpfrsqrt.awk \ + mpfrsqrt.ok \ mtchi18n.awk \ mtchi18n.in \ mtchi18n.ok \ @@ -1265,7 +1267,7 @@ EXTRA_TESTS = inftest regtest INET_TESTS = inetdayu inetdayt inetechu inetecht MACHINE_TESTS = double1 double2 fmtspcl intformat MPFR_TESTS = mpfrnr mpfrnegzero mpfrrnd mpfrieee mpfrexprange \ - mpfrsort mpfrbigint + mpfrsort mpfrsqrt mpfrbigint LOCALE_CHARSET_TESTS = \ asort asorti backbigs1 backsmalls1 backsmalls2 \ @@ -2169,6 +2171,11 @@ mpfrbigint: @$(AWK) -M -f "$(srcdir)"/$@.awk > _$@ 2>&1 @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +mpfrsqrt: + @echo $@ + @$(AWK) -M -f "$(srcdir)"/$@.awk > _$@ 2>&1 + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + jarebug:: @echo $@ @"$(srcdir)"/$@.sh "$(AWKPROG)" "$(srcdir)"/$@.awk "$(srcdir)"/$@.in "_$@" diff --git a/test/mpfrsqrt.awk b/test/mpfrsqrt.awk new file mode 100644 index 00000000..23a15c92 --- /dev/null +++ b/test/mpfrsqrt.awk @@ -0,0 +1,82 @@ +# Date: Sat, 02 Aug 2014 12:27:00 -0400 +# To: bug-gawk@gnu.org +# From: Katherine Wasserman <katie@wass.net> +# Message-ID: <E1XDc9F-0007BX-O1@eggs.gnu.org> +# Subject: [bug-gawk] GAWK 4.1 SQRT() bug +# +# In version 4.1.60 of GAWK the sqrt() function does not work correctly on bignums. +# Here's a demo of the problem along with, a function that does work correctly. +# +# Running this program (sqrt-bug.awk): +# -------------------------------------------------------------------- +BEGIN { +a=11111111111111111111111111111111111111111111111111111111111 +print sqrt(a^2) +#print sq_root(a^2) + +# ADR: Added for gawk-4.1-stable which doesn't have built-in div() function +if (PROCINFO["version"] < "4.1.60") + print sq_root2(a^2) +else + print sq_root(a^2) +} + + +function sq_root(x, temp,r,z) +{ temp=substr(x,1,length(x)/2) + 0 # a good first guess + z=0 + while (abs(z-temp)>1) + { z=temp + div(x,temp,r) + temp=r["quotient"] + temp + div(temp,2,r) + temp=r["quotient"] + } + return temp +} + +function sq_root2(x, temp,r,z) +{ temp=substr(x,1,length(x)/2) + 0 # a good first guess + z=0 + while (abs(z-temp)>1) + { z=temp + awk_div(x,temp,r) + temp=r["quotient"] + temp + awk_div(temp,2,r) + temp=r["quotient"] + } + return temp +} + +function abs(x) +{ return (x<0 ? -x : x) +} +# +# -------------------------------------------------------------------- +# gawk -M -f sqrt-bug.awk +# +# results in: +# 11111111111111111261130863809439559987542611609749437808640 +# 11111111111111111111111111111111111111111111111111111111111 +# +# Thanks, +# Katie +# + +# div --- do integer division + +function awk_div(numerator, denominator, result, i, save_PREC) +{ + save_PREC = PREC + PREC = 400 # good enough for this test + + split("", result) + + numerator = int(numerator) + denominator = int(denominator) + result["quotient"] = int(numerator / denominator) + result["remainder"] = int(numerator % denominator) + + PREC = save_PREC + return 0.0 +} diff --git a/test/mpfrsqrt.ok b/test/mpfrsqrt.ok new file mode 100644 index 00000000..16217c78 --- /dev/null +++ b/test/mpfrsqrt.ok @@ -0,0 +1,2 @@ +11111111111111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111111111111 |