~ubuntu-branches/ubuntu/wily/mysql-5.6/wily

« back to all changes in this revision

Viewing changes to strings/decimal.c

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2015-07-21 07:09:29 UTC
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: package-import@ubuntu.com-20150721070929-mg4dpqkgg3it1ajf
Tags: upstream-5.6.25
ImportĀ upstreamĀ versionĀ 5.6.25

Show diffs side-by-side

added added

removed removed

Lines of Context:
1064
1064
 
1065
1065
static int ull2dec(ulonglong from, decimal_t *to)
1066
1066
{
1067
 
  int intg1, error=E_DEC_OK;
1068
 
  ulonglong x=from;
 
1067
  int intg1;
 
1068
  int error= E_DEC_OK;
 
1069
  ulonglong x= from;
1069
1070
  dec1 *buf;
1070
1071
 
1071
1072
  sanity(to);
1072
1073
 
1073
 
  for (intg1=1; from >= DIG_BASE; intg1++, from/=DIG_BASE) ;
 
1074
  if (from == 0)
 
1075
    intg1= 1;
 
1076
  else
 
1077
  {
 
1078
    /* Count the number of decimal_digit_t's we need. */
 
1079
    for (intg1= 0; from != 0; intg1++, from/= DIG_BASE)
 
1080
      ;
 
1081
  }
1074
1082
  if (unlikely(intg1 > to->len))
1075
1083
  {
1076
 
    intg1=to->len;
1077
 
    error=E_DEC_OVERFLOW;
 
1084
    intg1= to->len;
 
1085
    error= E_DEC_OVERFLOW;
1078
1086
  }
1079
 
  to->frac=0;
1080
 
  to->intg=intg1*DIG_PER_DEC1;
 
1087
  to->frac= 0;
 
1088
  to->intg= intg1 * DIG_PER_DEC1;
1081
1089
 
1082
 
  for (buf=to->buf+intg1; intg1; intg1--)
 
1090
  for (buf= to->buf + intg1; intg1; intg1--)
1083
1091
  {
1084
 
    ulonglong y=x/DIG_BASE;
1085
 
    *--buf=(dec1)(x-y*DIG_BASE);
1086
 
    x=y;
 
1092
    ulonglong y= x / DIG_BASE;
 
1093
    *--buf=(dec1)(x - y * DIG_BASE);
 
1094
    x= y;
1087
1095
  }
1088
1096
  return error;
1089
1097
}