예제 #1
0
bool readint(int& n){ // Returns true on success, false on failure
	if(!adapt()) return false;
	bool ngtv = *(now - 1) == '-';
	for(n = 0; isdigit(*now); n = X10(n) + *now++ - '0');
	if(ngtv) n = -n;
	return true;
}
/* ------------------------------------------------------------------ */
uByte * decPackedFromNumber(uByte *bcd, Int length, Int *scale,
			    const decNumber *dn) {
  const Unit *up=dn->lsu;     /* Unit array pointer */
  uByte obyte, *out;	      /* current output byte, and where it goes */
  Int indigs=dn->digits;      /* digits processed */
  uInt cut=DECDPUN;	      /* downcounter per Unit */
  uInt u=*up;		      /* work */
  uInt nib;		      /* .. */
  #if DECDPUN<=4
  uInt temp;		      /* .. */
  #endif

  if (dn->digits>length*2-1		     /* too long .. */
   ||(dn->bits & DECSPECIAL)) return NULL;   /* .. or special -- hopeless */

  if (dn->bits&DECNEG) obyte=DECPMINUS;	     /* set the sign .. */
   else		       obyte=DECPPLUS;
  *scale=-dn->exponent;			     /* .. and scale */

  /* loop from lowest (rightmost) byte */
  out=bcd+length-1;			     /* -> final byte */
  for (; out>=bcd; out--) {
    if (indigs>0) {
      if (cut==0) {
	up++;
	u=*up;
	cut=DECDPUN;
	}
      #if DECDPUN<=4
	temp=(u*6554)>>16;	   /* fast /10 */
	nib=u-X10(temp);
	u=temp;
      #else
	nib=u%10;		   /* cannot use *6554 trick :-( */
	u=u/10;
      #endif
      obyte|=(nib<<4);
      indigs--;
      cut--;
      }
    *out=obyte;
    obyte=0;			   /* assume 0 */
    if (indigs>0) {
      if (cut==0) {
	up++;
	u=*up;
	cut=DECDPUN;
	}
      #if DECDPUN<=4
	temp=(u*6554)>>16;	   /* as above */
	obyte=(uByte)(u-X10(temp));
	u=temp;
      #else
	obyte=(uByte)(u%10);
	u=u/10;
      #endif
      indigs--;
      cut--;
      }
    } /* loop */

  return bcd;
  } /* decPackedFromNumber */
예제 #3
0
파일: decPacked.c 프로젝트: EmuxEvans/ion-c
/* ------------------------------------------------------------------ */
uByte * decPackedFromNumber(uByte *bcd, Int length, Int *scale,
                            const decNumber *dn) {
  const Unit *up=dn->lsu;     // Unit array pointer
  uByte obyte, *out;          // current output byte, and where it goes
  Int indigs=dn->digits;      // digits processed
  uInt cut=DECDPUN;           // downcounter per Unit
  uInt u=*up;                 // work
  uInt nib;                   // ..
  #if DECDPUN<=4
  uInt temp;                  // ..
  #endif

  if (dn->digits>length*2-1                  // too long ..
   ||(dn->bits & DECSPECIAL)) return NULL;   // .. or special -- hopeless

  if (dn->bits&DECNEG) obyte=DECPMINUS;      // set the sign ..
   else                obyte=DECPPLUS;
  *scale=-dn->exponent;                      // .. and scale

  // loop from lowest (rightmost) byte
  out=bcd+length-1;                          // -> final byte
  for (; out>=bcd; out--) {
    if (indigs>0) {
      if (cut==0) {
        up++;
        u=*up;
        cut=DECDPUN;
        }
      #if DECDPUN<=4
        temp=(u*6554)>>16;         // fast /10
        nib=u-X10(temp);
        u=temp;
      #else
        nib=u%10;                  // cannot use *6554 trick :-(
        u=u/10;
      #endif
      obyte|=(nib<<4);
      indigs--;
      cut--;
      }
    *out=obyte;
    obyte=0;                       // assume 0
    if (indigs>0) {
      if (cut==0) {
        up++;
        u=*up;
        cut=DECDPUN;
        }
      #if DECDPUN<=4
        temp=(u*6554)>>16;         // as above
        obyte=(uByte)(u-X10(temp));
        u=temp;
      #else
        obyte=(uByte)(u%10);
        u=u/10;
      #endif
      indigs--;
      cut--;
      }
    } // loop

  return bcd;
  } // decPackedFromNumber
예제 #4
0
inline void
TrtrsmLLN
( UnitOrNonUnit diag, F alpha, const DistMatrix<F>& L, DistMatrix<F>& X,
  bool checkIfSingular )
{
#ifndef RELEASE
    CallStackEntry entry("internal::TrtrsmLLN");
#endif
    const Grid& g = L.Grid();

    // Matrix views
    DistMatrix<F>
    LTL(g), LTR(g),  L00(g), L01(g), L02(g),
        LBL(g), LBR(g),  L10(g), L11(g), L12(g),
        L20(g), L21(g), L22(g);
    DistMatrix<F>
    XTL(g), XTR(g),  X00(g), X01(g), X02(g),
        XBL(g), XBR(g),  X10(g), X11(g), X12(g),
        X20(g), X21(g), X22(g);

    // Temporary distributions
    DistMatrix<F,STAR,STAR> L11_STAR_STAR(g);
    DistMatrix<F,MC,  STAR> L21_MC_STAR(g);
    DistMatrix<F,STAR,MR  > X10_STAR_MR(g);
    DistMatrix<F,STAR,VR  > X10_STAR_VR(g);
    DistMatrix<F,STAR,MR  > X11_STAR_MR(g);
    DistMatrix<F,STAR,STAR> X11_STAR_STAR(g);

    // Start the algorithm
    ScaleTrapezoid( alpha, LOWER, X );
    LockedPartitionDownDiagonal
    ( L, LTL, LTR,
      LBL, LBR, 0 );
    PartitionDownDiagonal
    ( X, XTL, XTR,
      XBL, XBR, 0 );
    while( XBR.Height() > 0 )
    {
        LockedRepartitionDownDiagonal
        ( LTL, /**/ LTR,  L00, /**/ L01, L02,
          /*************/ /******************/
          /**/       L10, /**/ L11, L12,
          LBL, /**/ LBR,  L20, /**/ L21, L22 );

        RepartitionDownDiagonal
        ( XTL, /**/ XTR,  X00, /**/ X01, X02,
          /*************/ /******************/
          /**/       X10, /**/ X11, X12,
          XBL, /**/ XBR,  X20, /**/ X21, X22 );

        L21_MC_STAR.AlignWith( X20 );
        X10_STAR_MR.AlignWith( X20 );
        X11_STAR_MR.AlignWith( X21 );
        //--------------------------------------------------------------------//
        L11_STAR_STAR = L11;
        X11_STAR_STAR = X11;
        X10_STAR_VR = X10;

        LocalTrsm
        ( LEFT, LOWER, NORMAL, diag, F(1), L11_STAR_STAR, X10_STAR_VR,
          checkIfSingular );
        LocalTrtrsm
        ( LEFT, LOWER, NORMAL, diag, F(1), L11_STAR_STAR, X11_STAR_STAR,
          checkIfSingular );
        X11 = X11_STAR_STAR;
        X11_STAR_MR = X11_STAR_STAR;
        MakeTriangular( LOWER, X11_STAR_MR );

        X10_STAR_MR = X10_STAR_VR;
        X10 = X10_STAR_MR;
        L21_MC_STAR = L21;

        LocalGemm
        ( NORMAL, NORMAL, F(-1), L21_MC_STAR, X10_STAR_MR, F(1), X20 );
        LocalGemm
        ( NORMAL, NORMAL, F(-1), L21_MC_STAR, X11_STAR_MR, F(1), X21 );
        //--------------------------------------------------------------------//

        SlideLockedPartitionDownDiagonal
        ( LTL, /**/ LTR,  L00, L01, /**/ L02,
          /**/       L10, L11, /**/ L12,
          /*************/ /******************/
          LBL, /**/ LBR,  L20, L21, /**/ L22 );

        SlidePartitionDownDiagonal
        ( XTL, /**/ XTR,  X00, X01, /**/ X02,
          /**/       X10, X11, /**/ X12,
          /*************/ /******************/
          XBL, /**/ XBR,  X20, X21, /**/ X22 );
    }
}