protected Dfp(final DfpField field,final String s){
  mant=new int[field.getRadixDigits()];
  sign=1;
  exp=0;
  nans=FINITE;
  this.field=field;
  boolean decimalFound=false;
  final int rsize=4;
  final int offset=4;
  final char[] striped=new char[getRadixDigits() * rsize + offset * 2];
  if (s.equals(POS_INFINITY_STRING)) {
    sign=(byte)1;
    nans=INFINITE;
    return;
  }
  if (s.equals(NEG_INFINITY_STRING)) {
    sign=(byte)-1;
    nans=INFINITE;
    return;
  }
  if (s.equals(NAN_STRING)) {
    sign=(byte)1;
    nans=QNAN;
    return;
  }
  int p=s.indexOf("e");
  if (p == -1) {
    p=s.indexOf("E");
  }
  final String fpdecimal;
  int sciexp=0;
  if (p != -1) {
    fpdecimal=s.substring(0,p);
    String fpexp=s.substring(p + 1);
    boolean negative=false;
    for (int i=0; i < fpexp.length(); i++) {
      if (fpexp.charAt(i) == '-') {
        negative=true;
        continue;
      }
      if (fpexp.charAt(i) >= '0' && fpexp.charAt(i) <= '9') {
        sciexp=sciexp * 10 + fpexp.charAt(i) - '0';
      }
    }
    if (negative) {
      sciexp=-sciexp;
    }
  }
 else {
    fpdecimal=s;
  }
  if (fpdecimal.indexOf("-") != -1) {
    sign=-1;
  }
  p=0;
  int decimalPos=0;
  for (; ; ) {
    if (fpdecimal.charAt(p) >= '1' && fpdecimal.charAt(p) <= '9') {
      break;
    }
    if (decimalFound && fpdecimal.charAt(p) == '0') {
      decimalPos--;
    }
    if (fpdecimal.charAt(p) == '.') {
      decimalFound=true;
    }
    p++;
    if (p == fpdecimal.length()) {
      break;
    }
  }
  int q=offset;
  striped[0]='0';
  striped[1]='0';
  striped[2]='0';
  striped[3]='0';
  int significantDigits=0;
  for (; ; ) {
    if (p == (fpdecimal.length())) {
      break;
    }
    if (q == mant.length * rsize + offset + 1) {
      break;
    }
    if (fpdecimal.charAt(p) == '.') {
      decimalFound=true;
      decimalPos=significantDigits;
      p++;
      continue;
    }
    if (fpdecimal.charAt(p) < '0' || fpdecimal.charAt(p) > '9') {
      p++;
      continue;
    }
    striped[q]=fpdecimal.charAt(p);
    q++;
    p++;
    significantDigits++;
  }
  if (decimalFound && q != offset) {
    for (; ; ) {
      q--;
      if (q == offset) {
        break;
      }
      if (striped[q] == '0') {
        significantDigits--;
      }
 else {
        break;
      }
    }
  }
  if (decimalFound && significantDigits == 0) {
    decimalPos=0;
  }
  if (!decimalFound) {
    decimalPos=q - offset;
  }
  q=offset;
  p=significantDigits - 1 + offset;
  while (p > q) {
    if (striped[p] != '0') {
      break;
    }
    p--;
  }
  int i=((rsize * 100) - decimalPos - sciexp % rsize) % rsize;
  q-=i;
  decimalPos+=i;
  while ((p - q) < (mant.length * rsize)) {
    for (i=0; i < rsize; i++) {
      striped[++p]='0';
    }
  }
  for (i=mant.length - 1; i >= 0; i--) {
    mant[i]=(striped[q] - '0') * 1000 + (striped[q + 1] - '0') * 100 + (striped[q + 2] - '0') * 10 + (striped[q + 3] - '0');
    q+=4;
  }
  exp=(decimalPos + sciexp) / rsize;
  if (q < striped.length) {
    round((striped[q] - '0') * 1000);
  }
}

protected Dfp ( final DfpField field , final String s ) { mant = new int [ field . getRadixDigits ( ) ] ; sign = 1 ; exp = 0 ; nans = FINITE ; this . field = field ; boolean decimalFound = false ; final int rsize = 4 ; final int offset = 4 ; final char [ ] striped = new char [ getRadixDigits ( ) * rsize + offset * 2 ] ; if ( s . equals ( POS_INFINITY_STRING ) ) { sign = ( byte ) 1 ; nans = INFINITE ; return ; } if ( s . equals ( NEG_INFINITY_STRING ) ) { sign = ( byte ) - 1 ; nans = INFINITE ; return ; } if ( s . equals ( NAN_STRING ) ) { sign = ( byte ) 1 ; nans = QNAN ; return ; } int p = s . indexOf ( "e" ) ; if ( p == - 1 ) { p = s . indexOf ( "E" ) ; } final String fpdecimal ; int sciexp = 0 ; if ( p != - 1 ) { fpdecimal = s . substring ( 0 , p ) ; String fpexp = s . substring ( p + 1 ) ; boolean negative = false ; for ( int i = 0 ; i < fpexp . length ( ) ; i ++ ) { if ( fpexp . charAt ( i ) == '-' ) { negative = true ; continue ; } if ( fpexp . charAt ( i ) >= '0' && fpexp . charAt ( i ) <= '9' ) { sciexp = sciexp * 10 + fpexp . charAt ( i ) - '0' ; } } if ( negative ) { sciexp = - sciexp ; } } else { fpdecimal = s ; } if ( fpdecimal . indexOf ( "-" ) != - 1 ) { sign = - 1 ; } p = 0 ; int decimalPos = 0 ; for ( ; ; ) { if ( fpdecimal . charAt ( p ) >= '1' && fpdecimal . charAt ( p ) <= '9' ) { break ; } if ( decimalFound && fpdecimal . charAt ( p ) == '0' ) { decimalPos -- ; } if ( fpdecimal . charAt ( p ) == '.' ) { decimalFound = true ; } p ++ ; if ( p == fpdecimal . length ( ) ) { break ; } } int q = offset ; striped [ 0 ] = '0' ; striped [ 1 ] = '0' ; striped [ 2 ] = '0' ; striped [ 3 ] = '0' ; int significantDigits = 0 ; for ( ; ; ) { if ( p == ( fpdecimal . length ( ) ) ) { break ; } if ( q == mant . length * rsize + offset + 1 ) { break ; } if ( fpdecimal . charAt ( p ) == '.' ) { decimalFound = true ; decimalPos = significantDigits ; p ++ ; continue ; } if ( fpdecimal . charAt ( p ) < '0' || fpdecimal . charAt ( p ) > '9' ) { p ++ ; continue ; } striped [ q ] = fpdecimal . charAt ( p ) ; q ++ ; p ++ ; significantDigits ++ ; } if ( decimalFound && q != offset ) { for ( ; ; ) { q -- ; if ( q == offset ) { break ; } if ( striped [ q ] == '0' ) { significantDigits -- ; } else { break ; } } } if ( decimalFound && significantDigits == 0 ) { decimalPos = 0 ; } if ( ! decimalFound ) { decimalPos = q - offset ; } q = offset ; p = significantDigits - 1 + offset ; while ( p > q ) { if ( striped [ p ] != '0' ) { break ; } p -- ; } int i = ( ( rsize * 100 ) - decimalPos - sciexp % rsize ) % rsize ; q -= i ; decimalPos += i ; while ( ( p - q ) < ( mant . length * rsize ) ) { for ( i = 0 ; i < rsize ; i ++ ) { striped [ ++ p ] = '0' ; } } for ( i = mant . length - 1 ; i >= 0 ; i -- ) { mant [ i ] = ( striped [ q ] - '0' ) * 1000 + ( striped [ q + 1 ] - '0' ) * 100 + ( striped [ q + 2 ] - '0' ) * 10 + ( striped [ q + 3 ] - '0' ) ; q += 4 ; } exp = ( decimalPos + sciexp ) / rsize ; if ( q < striped . length ) { round ( ( striped [ q ] - '0' ) * 1000 ) ; } }
create an instance from a string representation .
