Changeset 4fb4f3 in git


Ignore:
Timestamp:
Jul 22, 2010, 1:13:53 PM (14 years ago)
Author:
Frank Seelisch <seelisch@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'b52fc4b2495505785981d640dcf7eb3e456778ef')
Children:
c9208c6142738462cca70025492057ebce264baf
Parents:
ad0c5c42970dfab59d4ca1c9afc9fe369b894106
Message:
bug fix: ATTENTION: nr2mDivBy and nr2mIntDiv do not do what their names suggest

git-svn-id: file:///usr/local/Singular/svn/trunk@13046 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/rmodulo2m.cc

    rad0c5c r4fb4f3  
    151151{
    152152  NATNUMBER nn = (unsigned long)(NATNUMBER)n & r->nr2mModul;
    153   unsigned long l = r->nr2mModul >> 1; l++;
    154   if (l == 0)
    155     return (int)(signed long)(NATNUMBER)nn;
    156   else if ((NATNUMBER)nn > l)
     153  unsigned long l = r->nr2mModul >> 1; l++; /* now: l = 2^(m-1) */
     154  if ((NATNUMBER)nn > l)
    157155    return (int)((NATNUMBER)nn - r->nr2mModul - 1);
    158156  else
     
    210208}
    211209
     210/* This does not seem to be the predicate whether a
     211   is divisible by b in Z/2^m: if a is NULL then
     212   the answer is not necessarily TRUE. */
    212213BOOLEAN nr2mDivBy (number a, number b)
    213214{
    214   if ((NATNUMBER)a == 0) return TRUE;
    215   if ((NATNUMBER)b == 0) return FALSE;
    216   return ((NATNUMBER)a % (NATNUMBER)b) == 0;
     215  if (a == NULL)
     216  {
     217    NATNUMBER c = currRing->nr2mModul + 1;
     218    if (c != 0) /* i.e., if no overflow */
     219      return (c % (NATNUMBER)b) == 0;
     220    else
     221    {
     222      /* overflow: we need to check whether b
     223         is a power of 2: */
     224      c = (NATNUMBER)b;
     225      while (c != 0)
     226      {
     227        if ((c % 2) != 0) return FALSE;
     228        c = c >> 1;
     229      }
     230      return TRUE;
     231    }
     232  }
     233  else
     234    return ((NATNUMBER)a % (NATNUMBER)b) == 0;
    217235}
    218236
     
    391409}
    392410
    393 number nr2mIntDiv (number a,number b)
    394 {
    395   assume((NATNUMBER)b != 0);
    396   return (number) ((NATNUMBER) a / (NATNUMBER) b);
     411number nr2mIntDiv (number a, number b)
     412{
     413  if ((NATNUMBER)a == 0)
     414  {
     415    if ((NATNUMBER)b == 0)
     416      return (number)1;
     417    if ((NATNUMBER)b == 1)
     418      return (number)0;
     419    NATNUMBER c = currRing->nr2mModul + 1;
     420    if (c != 0) /* i.e., if no overflow */
     421      return (number)(c / (NATNUMBER)b);
     422    else
     423    {
     424      /* overflow: c = 2^32 resp. 2^64, depending on platform */
     425      int_number cc = (int_number)omAlloc(sizeof(mpz_t));
     426      mpz_init_set_ui(cc, currRing->nr2mModul); mpz_add_ui(cc, cc, 1);
     427      mpz_div_ui(cc, cc, (unsigned long)(NATNUMBER)b);
     428      unsigned long s = mpz_get_ui(cc);
     429      mpz_clear(cc); omFree((ADDRESS)cc);
     430      return (number)(NATNUMBER)s;
     431    }
     432  }
     433  else
     434  {
     435    if ((NATNUMBER)b == 0)
     436      return (number)0;
     437    return (number)((NATNUMBER) a / (NATNUMBER) b);
     438  }
    397439}
    398440
Note: See TracChangeset for help on using the changeset viewer.