~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/math/round.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-12-17 04:48:59 UTC
  • mto: This revision was merged to the branch mainline in revision 1246.
  • Revision ID: osullivan.padraig@gmail.com-20091217044859-qorpkp4911zypfv3
Added some dtrace probes for tracing the optimizer.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
21
 
 
22
 
#include <math.h>
23
 
#include <limits.h>
 
20
#include <drizzled/server_includes.h>
 
21
#include <drizzled/function/math/round.h>
24
22
 
25
23
#include <limits>
26
24
#include <algorithm>
27
25
 
28
 
#include "drizzled/function/math/round.h"
29
 
#include "drizzled/util/test.h"
30
 
 
31
 
namespace drizzled
32
 
{
33
 
 
34
 
extern const double log_10[309];
35
 
 
36
 
 
37
26
using namespace std;
38
27
 
39
28
void Item_func_round::fix_length_and_dec()
100
89
 
101
90
    precision-= decimals_delta - length_increase;
102
91
    decimals= min(decimals_to_set, DECIMAL_MAX_SCALE);
103
 
    max_length= class_decimal_precision_to_length(precision, decimals,
 
92
    max_length= my_decimal_precision_to_length(precision, decimals,
104
93
                                               unsigned_flag);
105
94
    break;
106
95
  }
203
192
 
204
193
  if (truncate)
205
194
    value= (unsigned_flag) ?
206
 
      (int64_t)(((uint64_t) value / tmp) * tmp) : (value / tmp) * tmp;
 
195
      ((uint64_t) value / tmp) * tmp : (value / tmp) * tmp;
207
196
  else
208
197
    value= (unsigned_flag || value >= 0) ?
209
 
      (int64_t)(my_unsigned_round((uint64_t) value, tmp)) :
 
198
      my_unsigned_round((uint64_t) value, tmp) :
210
199
      -(int64_t) my_unsigned_round((uint64_t) -value, tmp);
211
200
  return value;
212
201
}
213
202
 
214
203
 
215
 
type::Decimal *Item_func_round::decimal_op(type::Decimal *decimal_value)
 
204
my_decimal *Item_func_round::decimal_op(my_decimal *decimal_value)
216
205
{
217
 
  type::Decimal val, *value= args[0]->val_decimal(&val);
 
206
  my_decimal val, *value= args[0]->val_decimal(&val);
218
207
  int64_t dec= args[1]->val_int();
219
208
 
220
209
  if (dec >= 0 || args[1]->unsigned_flag)
223
212
    dec= INT_MIN;
224
213
 
225
214
  if (!(null_value= (args[0]->null_value || args[1]->null_value ||
226
 
                     class_decimal_round(E_DEC_FATAL_ERROR, value, (int) dec,
 
215
                     my_decimal_round(E_DEC_FATAL_ERROR, value, (int) dec,
227
216
                                      truncate, decimal_value) > 1)))
228
217
  {
229
218
    decimal_value->frac= decimals;
232
221
  return 0;
233
222
}
234
223
 
235
 
} /* namespace drizzled */