]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - math/atest-exp.c
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / math / atest-exp.c
index 4cab953e46e3ae646b0bec5226e93e60e027d9ba..b3d73aec4fdf0972de1f30479bf265990e3f8ef3 100644 (file)
@@ -1,25 +1,24 @@
-/* Copyright (C) 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1997-2019 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Geoffrey Keating <Geoff.Keating@anu.edu.au>, 1997.
 
    The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Library General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
 
    The GNU C Library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Library General Public License for more details.
+   Lesser General Public License for more details.
 
-   You should have received a copy of the GNU Library General Public
-   License along with the GNU C Library; see the file COPYING.LIB.  If not,
-   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
 
 #include <stdio.h>
 #include <math.h>
-#include <stdlib/gmp.h>
+#include <gmp.h>
 #include <string.h>
 #include <limits.h>
 #include <assert.h>
@@ -40,7 +39,7 @@ static const char exp1[102] = "2" /* point */
 "84d9045190cfef324e7738926cfbe5f4bf8d8d8c31d763da07";
 static const char hexdig[] = "0123456789abcdef";
 
-void
+static void
 print_mpn_hex (const mp_limb_t *x, unsigned size)
 {
    char value[size + 1];
@@ -56,13 +55,13 @@ print_mpn_hex (const mp_limb_t *x, unsigned size)
    fputs (value, stdout);
 }
 
-void
+static void
 exp_mpn (mp1 ex, mp1 x)
 {
    unsigned n;
    mp1 xp;
    mp2 tmp;
-   mp_limb_t chk, round;
+   mp_limb_t chk __attribute__ ((unused));
    mp1 tol;
 
    memset (xp, 0, sizeof (mp1));
@@ -80,7 +79,7 @@ exp_mpn (mp1 ex, mp1 x)
        mpn_mul_n (tmp, xp, x, SZ);
        assert (tmp[SZ * 2 - 1] == 0);
        if (n > 0)
-        round = mpn_divmod_1 (xp, tmp + FRAC / mpbpl, SZ, n);
+        mpn_divmod_1 (xp, tmp + FRAC / mpbpl, SZ, n);
        chk = mpn_add_n (ex, ex, xp, SZ);
        assert (chk == 0);
        n++;
@@ -96,15 +95,15 @@ mpn_bitsize(const mp_limb_t *SRC_PTR, mp_size_t SIZE)
    for (i = SIZE - 1; i > 0; i--)
      if (SRC_PTR[i] != 0)
        break;
-   for (j = mpbpl - 1; j > 0; j--)
-     if ((SRC_PTR[i] & 1 << j) != 0)
+   for (j = mpbpl - 1; j >= 0; j--)
+     if ((SRC_PTR[i] & (mp_limb_t)1 << j) != 0)
        break;
 
-   return i * 32 + j;
+   return i * mpbpl + j;
 }
 
-int
-main (void)
+static int
+do_test (void)
 {
    mp1 ex, x, xt, e2, e3;
    int i;
@@ -141,7 +140,7 @@ main (void)
 
       e2s = mpn_bitsize (e2,SZ);
       e3s = mpn_bitsize (e3,SZ);
-      if (e3s > 1 && e2s - e3s < 54)
+      if (e3s >= 0 && e2s - e3s < 54)
        {
 #if PRINT_ERRORS
          printf ("%06x ", i * (0x100000 / (1 << N2)));
@@ -171,8 +170,10 @@ main (void)
 
    memset (e2, '\0', sizeof (mp1));
    for (i = -1; i < 100 && i < FRAC / 4; i++)
-     e2[(FRAC - i * 4 - 4) / mpbpl] |= (strchr (hexdig, exp1[i + 1]) - hexdig
-                                       << (FRAC - i * 4 - 4) % mpbpl);
+     e2[(FRAC - i * 4 - 4) / mpbpl] |= ((mp_limb_t) (strchr (hexdig,
+                                                            exp1[i + 1])
+                                                    - hexdig)
+                                       << (FRAC - i * 4 - 4) % mpbpl);
 
    if (mpn_cmp (ex, e2, SZ) >= 0)
      mpn_sub_n (e3, ex, e2, SZ);
@@ -189,3 +190,7 @@ main (void)
 
    return failures == 0 ? 0 : 1;
 }
+
+#define TIMEOUT 200
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"