abc/src/bdd/cudd/cuddApa.c
/**Function********************************************************************

  Synopsis    [Divides an arbitrary precision integer by an integer.]

  Description [Divides an arbitrary precision integer by a 32-bit
  unsigned integer. Returns the remainder of the division. This
  procedure relies on the assumption that the number of bits of a
  DdApaDigit plus the number of bits of an unsigned int is less the
  number of bits of the mantissa of a double. This guarantees that the
  product of a DdApaDigit and an unsigned int can be represented
  without loss of precision by a double. On machines where this
  assumption is not satisfied, this procedure will malfunction.]

  SideEffects [The quotient is returned in parameter <code>quotient</code>.]

  SeeAlso     [Cudd_ApaShortDivision]

******************************************************************************/
Function
Synopsis    [Divides an arbitrary precision integer by an integer.]

Description [Divides an arbitrary precision integer by a 32-bit
unsigned integer. Returns the remainder of the division. This
procedure relies on the assumption that the number of bits of a
DdApaDigit plus the number of bits of an unsigned int is less the
number of bits of the mantissa of a double. This guarantees that the
product of a DdApaDigit and an unsigned int can be represented
without loss of precision by a double. On machines where this
assumption is not satisfied, this procedure will malfunction.]

SideEffects [The quotient is returned in parameter quotient.]


Function Synopsis [ Divides an arbitrary precision integer by an integer . ] Description [ Divides an arbitrary precision integer by a 32 - bit unsigned integer . Returns the remainder of the division . This procedure relies on the assumption that the number of bits of a DdApaDigit plus the number of bits of an unsigned int is less the number of bits of the mantissa of a double . This guarantees that the product of a DdApaDigit and an unsigned int can be represented without loss of precision by a double . On machines where this assumption is not satisfied this procedure will malfunction . ] SideEffects [ The quotient is returned in parameter quotient . ]
unsigned int
Cudd_ApaIntDivision(
  int  digits,
  DdApaNumber dividend,
  unsigned int divisor,
  DdApaNumber quotient)
{
    int i;
    double partial;
    unsigned int remainder = 0;
    double ddiv = (double) divisor;
    for (i = 0; i < digits; i++) {
        partial = (double) remainder * DD_APA_BASE + dividend[i];
        quotient[i] = (DdApaDigit) (partial / ddiv);
        remainder = (unsigned int) (partial - ((double)quotient[i] * ddiv));
    }
    return(remainder);
}
unsigned int Cudd_ApaIntDivision ( int digits , DdApaNumber dividend , unsigned int divisor , DdApaNumber quotient ) { int i ; double partial ; unsigned int remainder = 0 ; double ddiv = ( double ) divisor ; for ( i = 0 ; i < digits ; i ++ ) { partial = ( double ) remainder * DD_APA_BASE + dividend [ i ] ; quotient [ i ] = ( DdApaDigit ) ( partial / ddiv ) ; remainder = ( unsigned int ) ( partial - ( ( double ) quotient [ i ] * ddiv ) ) ; } return ( remainder ) ; }
Function
Synopsis    [Divides an arbitrary precision integer by an integer.]
Function Synopsis [ Divides an arbitrary precision integer by an integer . ]