summaryrefslogtreecommitdiff
path: root/cos.c
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2005-10-30 13:20:46 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2005-10-30 13:20:46 +0000
commite0b73cd20c1a05dc1018d3b9963d4446ae8e5a95 (patch)
tree46fec3a0965299bcf935c9276d82953ee56f9b43 /cos.c
parent81d0fe7e5bf08752226da35688d6fdc4b86dd024 (diff)
downloadmpfr-e0b73cd20c1a05dc1018d3b9963d4446ae8e5a95.tar.gz
3 corrections in cos.c concerning maxi:
* corrected a comment; * failed if sizeof(int) <= sizeof(long) / 2; * now take possible padding bits into account. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@3910 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'cos.c')
-rw-r--r--cos.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/cos.c b/cos.c
index bf3abd415..0b704c86d 100644
--- a/cos.c
+++ b/cos.c
@@ -19,6 +19,8 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Place, Fifth Floor, Boston,
MA 02110-1301, USA. */
+#include <limits.h>
+
#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
@@ -36,8 +38,16 @@ mpfr_cos2_aux (mpfr_ptr f, mpfr_srcptr r)
mp_prec_t p, q;
unsigned long i, maxi, imax;
- /* compute maximal i such that i*(i+1) fits in an unsigned long */
- maxi = 1 << (4 * sizeof(unsigned long));
+ /* compute minimal i such that i*(i+1) does not fit in an unsigned long,
+ assuming that there are no padding bits. */
+ maxi = 1UL << (CHAR_BIT * sizeof(unsigned long) / 2);
+ if (maxi * (maxi-1) == 0) /* test checked at compile time */
+ {
+ /* can occur only when there are padding bits. */
+ do
+ maxi /= 2;
+ while (maxi * (maxi-1) == 0);
+ }
mpz_init (x);
mpz_init (s);