-/* Copyright (C) 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1997-2024 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>
"300240b760e6fa96a94430a52d0e9e43f3450e3b8ff99bc934";
static const char hexdig[] = "0123456789abcdef";
-void
+static void
print_mpn_hex (const mp_limb_t *x, unsigned size)
{
char value[size + 1];
fputs (value, stdout);
}
-void
+static void
sincosx_mpn (mp1 si, mp1 co, mp1 xx, mp1 ix)
{
int i;
mp2 s[4], c[4];
mp1 tmp, x;
- mp_limb_t chk, round;
if (ix == NULL)
{
for (i = 0; i < 1 << N; i++)
{
#define add_shift_mulh(d,x,s1,s2,sh,n) \
- /* d = (n ? -1 : 1) * (s1 + (s2>>sh)) * x / (1>>N); */ \
do { \
if (s2 != NULL) { \
if (sh > 0) { \
assert (sh < mpbpl); \
mpn_lshift (tmp, s1, SZ, sh); \
- chk = (n ? mpn_sub_n : mpn_add_n)(tmp,tmp,s2+FRAC/mpbpl,SZ); \
- } else \
- chk = (n ? mpn_sub_n : mpn_add_n)(tmp,s1,s2+FRAC/mpbpl,SZ); \
- /* assert(chk == 0); */ \
+ if (n) \
+ mpn_sub_n (tmp,tmp,s2+FRAC/mpbpl,SZ); \
+ else \
+ mpn_add_n (tmp,tmp,s2+FRAC/mpbpl,SZ); \
+ } else { \
+ if (n) \
+ mpn_sub_n (tmp,s1,s2+FRAC/mpbpl,SZ); \
+ else \
+ mpn_add_n (tmp,s1,s2+FRAC/mpbpl,SZ); \
+ } \
mpn_mul_n(d,tmp,x,SZ); \
} else \
mpn_mul_n(d,s1,x,SZ); \
- /* assert(d[SZ*2-1] == 0); */ \
assert(N+sh < mpbpl); \
if (N+sh > 0) mpn_rshift(d,d,2*SZ,N+sh); \
} while(0)
#define summ(d,ss,s,n) \
- /* d = ss +/- (s[0]+2*s[1]+2*s[2]+s[3])/6; */ \
do { \
- chk = mpn_add_n(tmp,s[1]+FRAC/mpbpl,s[2]+FRAC/mpbpl,SZ); \
+ mpn_add_n(tmp,s[1]+FRAC/mpbpl,s[2]+FRAC/mpbpl,SZ); \
mpn_lshift(tmp,tmp,SZ,1); \
- chk |= mpn_add_n(tmp,tmp,s[0]+FRAC/mpbpl,SZ); \
- chk |= mpn_add_n(tmp,tmp,s[3]+FRAC/mpbpl,SZ); \
- round = mpn_divmod_1(tmp,tmp,SZ,6); \
- /* chk |= mpn_add_1(tmp,tmp,SZ, (round > 3) ); */ \
- chk |= (n ? mpn_sub_n : mpn_add_n)(d,ss,tmp,SZ); \
- /* assert(chk == 0); */ \
+ mpn_add_n(tmp,tmp,s[0]+FRAC/mpbpl,SZ); \
+ mpn_add_n(tmp,tmp,s[3]+FRAC/mpbpl,SZ); \
+ mpn_divmod_1(tmp,tmp,SZ,6); \
+ if (n) \
+ mpn_sub_n (d,ss,tmp,SZ); \
+ else \
+ mpn_add_n (d,ss,tmp,SZ); \
} while (0)
add_shift_mulh (s[0], x, co, NULL, 0, 0); /* s0 = h * c; */
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 si, co, x, ox, xt, s2, c2, s3, c3;
int i;
s3s = mpn_bitsize (s3, SZ);
c2s = mpn_bitsize (c2, SZ);
c3s = mpn_bitsize (c3, SZ);
- if (s3s > 1 && s2s - s3s < 54
- || c3s > 1 && c2s - c3s < 54
+ if ((s3s >= 0 && s2s - s3s < 54)
+ || (c3s >= 0 && c2s - c3s < 54)
|| 0)
{
#if PRINT_ERRORS
print_mpn_hex (c2, (FRAC / 4) + 1);
putchar ('\n');
printf (" %c%c ",
- s2s-s3s < 54 ? s2s - s3s == 53 ? 'e' : 'F' : 'P',
- c2s-c3s < 54 ? c2s - c3s == 53 ? 'e' : 'F' : 'P');
+ s3s >= 0 && s2s-s3s < 54 ? s2s - s3s == 53 ? 'e' : 'F' : 'P',
+ c3s >= 0 && c2s-c3s < 54 ? c2s - c3s == 53 ? 'e' : 'F' : 'P');
print_mpn_hex (s3, (FRAC / 4) + 1);
putchar (' ');
print_mpn_hex (c3, (FRAC / 4) + 1);
memset (c2, 0, sizeof (mp1));
for (i = 0; i < 100 && i < FRAC / 4; i++)
{
- s2[(FRAC - i * 4 - 4) / mpbpl] |= (strchr (hexdig, sin1[i]) - hexdig
- << (FRAC - i * 4 - 4) % mpbpl);
- c2[(FRAC - i * 4 - 4) / mpbpl] |= (strchr (hexdig, cos1[i]) - hexdig
+ s2[(FRAC - i * 4 - 4) / mpbpl] |= ((mp_limb_t) (strchr (hexdig, sin1[i])
+ - hexdig)
+ << (FRAC - i * 4 - 4) % mpbpl);
+ c2[(FRAC - i * 4 - 4) / mpbpl] |= ((mp_limb_t) (strchr (hexdig, cos1[i])
+ - hexdig)
<< (FRAC - i * 4 - 4) % mpbpl);
}
return (sin_failures == 0 && cos_failures == 0) ? 0 : 1;
}
+
+#define TIMEOUT 600
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"