~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item_func.cc

code clean move Item_func_ceiling, Item_func_cos, Item_func_sin, Item_func_tan, Item_func_int_val to functions directory

Show diffs side-by-side

added added

removed removed

Lines of Context:
150
150
  return copy_or_same(thd);
151
151
}
152
152
 
153
 
double Item_func_cos::val_real()
154
 
{
155
 
  assert(fixed == 1);
156
 
  double value= args[0]->val_real();
157
 
  if ((null_value=args[0]->null_value))
158
 
    return 0.0;
159
 
  return cos(value);
160
 
}
161
 
 
162
 
double Item_func_sin::val_real()
163
 
{
164
 
  assert(fixed == 1);
165
 
  double value= args[0]->val_real();
166
 
  if ((null_value=args[0]->null_value))
167
 
    return 0.0;
168
 
  return sin(value);
169
 
}
170
 
 
171
 
double Item_func_tan::val_real()
172
 
{
173
 
  assert(fixed == 1);
174
 
  double value= args[0]->val_real();
175
 
  if ((null_value=args[0]->null_value))
176
 
    return 0.0;
177
 
  return fix_result(tan(value));
178
 
}
179
 
 
180
 
 
181
153
// Shift-functions, same as << and >> in C/C++
182
154
 
183
155
 
232
204
  decimals=0;
233
205
}
234
206
 
235
 
void Item_func_int_val::fix_num_length_and_dec()
236
 
{
237
 
  max_length= args[0]->max_length - (args[0]->decimals ?
238
 
                                     args[0]->decimals + 1 :
239
 
                                     0) + 2;
240
 
  uint32_t tmp= float_length(decimals);
241
 
  set_if_smaller(max_length,tmp);
242
 
  decimals= 0;
243
 
}
244
 
 
245
 
 
246
 
void Item_func_int_val::find_num_type()
247
 
{
248
 
  switch(hybrid_type= args[0]->result_type())
249
 
  {
250
 
  case STRING_RESULT:
251
 
  case REAL_RESULT:
252
 
    hybrid_type= REAL_RESULT;
253
 
    max_length= float_length(decimals);
254
 
    break;
255
 
  case INT_RESULT:
256
 
  case DECIMAL_RESULT:
257
 
    /*
258
 
      -2 because in most high position can't be used any digit for int64_t
259
 
      and one position for increasing value during operation
260
 
    */
261
 
    if ((args[0]->max_length - args[0]->decimals) >=
262
 
        (DECIMAL_LONGLONG_DIGITS - 2))
263
 
    {
264
 
      hybrid_type= DECIMAL_RESULT;
265
 
    }
266
 
    else
267
 
    {
268
 
      unsigned_flag= args[0]->unsigned_flag;
269
 
      hybrid_type= INT_RESULT;
270
 
    }
271
 
    break;
272
 
  default:
273
 
    assert(0);
274
 
  }
275
 
  return;
276
 
}
277
 
 
278
 
 
279
 
int64_t Item_func_ceiling::int_op()
280
 
{
281
 
  int64_t result;
282
 
  switch (args[0]->result_type()) {
283
 
  case INT_RESULT:
284
 
    result= args[0]->val_int();
285
 
    null_value= args[0]->null_value;
286
 
    break;
287
 
  case DECIMAL_RESULT:
288
 
  {
289
 
    my_decimal dec_buf, *dec;
290
 
    if ((dec= Item_func_ceiling::decimal_op(&dec_buf)))
291
 
      my_decimal2int(E_DEC_FATAL_ERROR, dec, unsigned_flag, &result);
292
 
    else
293
 
      result= 0;
294
 
    break;
295
 
  }
296
 
  default:
297
 
    result= (int64_t)Item_func_ceiling::real_op();
298
 
  };
299
 
  return result;
300
 
}
301
 
 
302
 
 
303
 
double Item_func_ceiling::real_op()
304
 
{
305
 
  /*
306
 
    the volatile's for BUG #3051 to calm optimizer down (because of gcc's
307
 
    bug)
308
 
  */
309
 
  volatile double value= args[0]->val_real();
310
 
  null_value= args[0]->null_value;
311
 
  return ceil(value);
312
 
}
313
 
 
314
 
 
315
 
my_decimal *Item_func_ceiling::decimal_op(my_decimal *decimal_value)
316
 
{
317
 
  my_decimal val, *value= args[0]->val_decimal(&val);
318
 
  if (!(null_value= (args[0]->null_value ||
319
 
                     my_decimal_ceiling(E_DEC_FATAL_ERROR, value,
320
 
                                        decimal_value) > 1)))
321
 
    return decimal_value;
322
 
  return 0;
323
 
}
324
 
 
325
 
 
326
207
int64_t Item_func_floor::int_op()
327
208
{
328
209
  int64_t result;