~jlukas79/+junk/mysql-server

« back to all changes in this revision

Viewing changes to sql/my_decimal.h

manual merge 6.0-main --> 6.0-bka-review

Show diffs side-by-side

added added

removed removed

Lines of Context:
114
114
  bool sign() const { return decimal_t::sign; }
115
115
  void sign(bool s) { decimal_t::sign= s; }
116
116
  uint precision() const { return intg + frac; }
 
117
 
 
118
  /** Swap two my_decimal values */
 
119
  void swap(my_decimal &rhs)
 
120
  {
 
121
    swap_variables(my_decimal, *this, rhs);
 
122
    /* Swap the buffer pointers back */
 
123
    swap_variables(decimal_digit_t *, buf, rhs.buf);
 
124
  }
117
125
};
118
126
 
119
127
 
169
177
inline uint my_decimal_length_to_precision(uint length, uint scale,
170
178
                                           bool unsigned_flag)
171
179
{
172
 
  return (uint) (length - (scale>0 ? 1:0) - (unsigned_flag ? 0:1));
 
180
  /* Precision can't be negative thus ignore unsigned_flag when length is 0. */
 
181
  DBUG_ASSERT(length || !scale);
 
182
  return (uint) (length - (scale>0 ? 1:0) -
 
183
                 (unsigned_flag || !length ? 0:1));
173
184
}
174
185
 
175
186
inline uint32 my_decimal_precision_to_length(uint precision, uint8 scale,
176
187
                                             bool unsigned_flag)
177
188
{
 
189
  /*
 
190
    When precision is 0 it means that original length was also 0. Thus
 
191
    unsigned_flag is ignored in this case.
 
192
  */
 
193
  DBUG_ASSERT(precision || !scale);
178
194
  set_if_smaller(precision, DECIMAL_MAX_PRECISION);
179
 
  return (uint32)(precision + (scale>0 ? 1:0) + (unsigned_flag ? 0:1));
 
195
  return (uint32)(precision + (scale>0 ? 1:0) +
 
196
                  (unsigned_flag || !precision ? 0:1));
180
197
}
181
198
 
182
199
inline