~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Monty Taylor
  • Date: 2008-07-15 21:40:58 UTC
  • mfrom: (77.1.113 codestyle32)
  • mto: This revision was merged to the branch mainline in revision 176.
  • Revision ID: mordred@camelot-20080715214058-rm3phulldos9xehv
Merged from codestyle.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
19
 
 
20
 
#include <config.h>
21
 
 
22
 
#include <drizzled/function/math/minus.h>
23
 
#include <drizzled/type/decimal.h>
24
 
 
25
 
namespace drizzled
26
 
{
27
 
 
28
 
/**
29
 
  The following function is here to allow the user to force
30
 
  subtraction of UNSIGNED BIGINT to return negative values.
31
 
*/
32
 
 
33
 
void Item_func_minus::fix_length_and_dec()
34
 
{
35
 
  Item_num_op::fix_length_and_dec();
36
 
  if (unsigned_flag)
37
 
    unsigned_flag= 0;
38
 
}
39
 
 
40
 
 
41
 
double Item_func_minus::real_op()
42
 
{
43
 
  double value= args[0]->val_real() - args[1]->val_real();
44
 
  if ((null_value=args[0]->null_value || args[1]->null_value))
45
 
    return 0.0;
46
 
  return fix_result(value);
47
 
}
48
 
 
49
 
 
50
 
int64_t Item_func_minus::int_op()
51
 
{
52
 
  int64_t value=args[0]->val_int() - args[1]->val_int();
53
 
  if ((null_value=args[0]->null_value || args[1]->null_value))
54
 
    return 0;
55
 
  return value;
56
 
}
57
 
 
58
 
/**
59
 
  See Item_func_plus::decimal_op for comments.
60
 
*/
61
 
 
62
 
type::Decimal *Item_func_minus::decimal_op(type::Decimal *decimal_value)
63
 
{
64
 
  type::Decimal value1, *val1;
65
 
  type::Decimal value2, *val2=
66
 
 
67
 
  val1= args[0]->val_decimal(&value1);
68
 
  if ((null_value= args[0]->null_value))
69
 
    return 0;
70
 
  val2= args[1]->val_decimal(&value2);
71
 
  if (!(null_value= (args[1]->null_value ||
72
 
                     (class_decimal_sub(E_DEC_FATAL_ERROR, decimal_value, val1,
73
 
                                     val2) > 3))))
74
 
    return decimal_value;
75
 
  return 0;
76
 
}
77
 
 
78
 
} /* namespace drizzled */