~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to strings/decimal.c

Merged in Jay's tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1039
1039
  {
1040
1040
    uint64_t y=x;
1041
1041
    x=x*DIG_BASE + *buf++;
1042
 
    if (unlikely(y > ((uint64_t) ULONGLONG_MAX/DIG_BASE) || x < y))
 
1042
    if (unlikely(y > ((uint64_t) UINT64_MAX/DIG_BASE) || x < y))
1043
1043
    {
1044
 
      *to=ULONGLONG_MAX;
 
1044
      *to=UINT64_MAX;
1045
1045
      return E_DEC_OVERFLOW;
1046
1046
    }
1047
1047
  }
1064
1064
    /*
1065
1065
      Attention: trick!
1066
1066
      we're calculating -|from| instead of |from| here
1067
 
      because |LONGLONG_MIN| > LONGLONG_MAX
 
1067
      because |INT64_MIN| > INT64_MAX
1068
1068
      so we can convert -9223372036854775808 correctly
1069
1069
    */
1070
1070
    x=x*DIG_BASE - *buf++;
1071
 
    if (unlikely(y < (LONGLONG_MIN/DIG_BASE) || x > y))
 
1071
    if (unlikely(y < (INT64_MIN/DIG_BASE) || x > y))
1072
1072
    {
1073
1073
      /*
1074
1074
        the decimal is bigger than any possible integer
1075
1075
        return border integer depending on the sign
1076
1076
      */
1077
 
      *to= from->sign ? LONGLONG_MIN : LONGLONG_MAX;
 
1077
      *to= from->sign ? INT64_MIN : INT64_MAX;
1078
1078
      return E_DEC_OVERFLOW;
1079
1079
    }
1080
1080
  }
1081
1081
  /* boundary case: 9223372036854775808 */
1082
 
  if (unlikely(from->sign==0 && x == LONGLONG_MIN))
 
1082
  if (unlikely(from->sign==0 && x == INT64_MIN))
1083
1083
  {
1084
 
    *to= LONGLONG_MAX;
 
1084
    *to= INT64_MAX;
1085
1085
    return E_DEC_OVERFLOW;
1086
1086
  }
1087
1087
 
1528
1528
  buf1+=intg0+frac0-1;
1529
1529
  if (scale == frac0*DIG_PER_DEC1)
1530
1530
  {
1531
 
    int do_inc= FALSE;
 
1531
    int do_inc= false;
1532
1532
    DBUG_ASSERT(frac0+intg0 >= 0);
1533
1533
    switch (round_digit) {
1534
1534
    case 0:
1538
1538
      {
1539
1539
        if (*p0)
1540
1540
        {
1541
 
          do_inc= TRUE;
 
1541
          do_inc= true;
1542
1542
          break;
1543
1543
        }
1544
1544
      }