~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: lbieber
  • Date: 2010-10-06 16:34:16 UTC
  • mfrom: (1816.1.3 build)
  • Revision ID: lbieber@orisndriz08-20101006163416-ea0sl59qgpglk21y
Merge Monty - Change the requirement from either libinnodb to libhaildb. Also, tied it to version 2.2
Merge Andrew - fix bug 650935: remove --compress from all clients
Merge Andrew - fix bug 653471: Add -A to drizzle client
Merge Travis - 621861 = To change C structs to C++ classes in Drizzle

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
26
26
#include <algorithm>
27
27
 
28
28
#include "drizzled/function/math/round.h"
29
 
#include "drizzled/util/test.h"
30
29
 
31
30
namespace drizzled
32
31
{
100
99
 
101
100
    precision-= decimals_delta - length_increase;
102
101
    decimals= min(decimals_to_set, DECIMAL_MAX_SCALE);
103
 
    max_length= class_decimal_precision_to_length(precision, decimals,
 
102
    max_length= my_decimal_precision_to_length(precision, decimals,
104
103
                                               unsigned_flag);
105
104
    break;
106
105
  }
203
202
 
204
203
  if (truncate)
205
204
    value= (unsigned_flag) ?
206
 
      (int64_t)(((uint64_t) value / tmp) * tmp) : (value / tmp) * tmp;
 
205
      ((uint64_t) value / tmp) * tmp : (value / tmp) * tmp;
207
206
  else
208
207
    value= (unsigned_flag || value >= 0) ?
209
 
      (int64_t)(my_unsigned_round((uint64_t) value, tmp)) :
 
208
      my_unsigned_round((uint64_t) value, tmp) :
210
209
      -(int64_t) my_unsigned_round((uint64_t) -value, tmp);
211
210
  return value;
212
211
}
213
212
 
214
213
 
215
 
type::Decimal *Item_func_round::decimal_op(type::Decimal *decimal_value)
 
214
my_decimal *Item_func_round::decimal_op(my_decimal *decimal_value)
216
215
{
217
 
  type::Decimal val, *value= args[0]->val_decimal(&val);
 
216
  my_decimal val, *value= args[0]->val_decimal(&val);
218
217
  int64_t dec= args[1]->val_int();
219
218
 
220
219
  if (dec >= 0 || args[1]->unsigned_flag)
223
222
    dec= INT_MIN;
224
223
 
225
224
  if (!(null_value= (args[0]->null_value || args[1]->null_value ||
226
 
                     class_decimal_round(E_DEC_FATAL_ERROR, value, (int) dec,
 
225
                     my_decimal_round(E_DEC_FATAL_ERROR, value, (int) dec,
227
226
                                      truncate, decimal_value) > 1)))
228
227
  {
229
228
    decimal_value->frac= decimals;