~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2009-08-04 06:21:17 UTC
  • mfrom: (1108.2.2 merge)
  • Revision ID: brian@gaz-20090804062117-fef8x6y3ydzrvab3
Merge Brian

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
 
#include <math.h>
 
20
#include <drizzled/server_includes.h>
22
21
#include <drizzled/function/math/mod.h>
23
 
#include <drizzled/type/decimal.h>
24
22
 
25
23
#include <algorithm>
26
24
 
27
25
using namespace std;
28
26
 
29
 
namespace drizzled
30
 
{
31
 
 
32
27
int64_t Item_func_mod::int_op()
33
28
{
34
29
  assert(fixed == 1);
37
32
  int64_t result;
38
33
 
39
34
  if ((null_value= args[0]->null_value || args[1]->null_value))
40
 
    return 0;
 
35
    return 0; /* purecov: inspected */
41
36
  if (val2 == 0)
42
37
  {
43
38
    signal_divide_by_null();
49
44
      ((uint64_t) value) % ((uint64_t) val2) : ((uint64_t) value) % val2;
50
45
  else
51
46
    result= args[1]->unsigned_flag ?
52
 
      (int64_t)(value % ((uint64_t) val2)) : (int64_t)(value % val2);
 
47
      value % ((uint64_t) val2) : value % val2;
53
48
 
54
49
  return result;
55
50
}
60
55
  double value= args[0]->val_real();
61
56
  double val2=  args[1]->val_real();
62
57
  if ((null_value= args[0]->null_value || args[1]->null_value))
63
 
    return 0.0;
 
58
    return 0.0; /* purecov: inspected */
64
59
  if (val2 == 0.0)
65
60
  {
66
61
    signal_divide_by_null();
70
65
}
71
66
 
72
67
 
73
 
type::Decimal *Item_func_mod::decimal_op(type::Decimal *decimal_value)
 
68
my_decimal *Item_func_mod::decimal_op(my_decimal *decimal_value)
74
69
{
75
 
  type::Decimal value1, *val1;
76
 
  type::Decimal value2, *val2;
 
70
  my_decimal value1, *val1;
 
71
  my_decimal value2, *val2;
77
72
 
78
73
  val1= args[0]->val_decimal(&value1);
79
74
  if ((null_value= args[0]->null_value))
81
76
  val2= args[1]->val_decimal(&value2);
82
77
  if ((null_value= args[1]->null_value))
83
78
    return 0;
84
 
  switch (class_decimal_mod(E_DEC_FATAL_ERROR & ~E_DEC_DIV_ZERO, decimal_value,
 
79
  switch (my_decimal_mod(E_DEC_FATAL_ERROR & ~E_DEC_DIV_ZERO, decimal_value,
85
80
                         val1, val2)) {
86
81
  case E_DEC_TRUNCATED:
87
82
  case E_DEC_OK:
109
104
  unsigned_flag= args[0]->unsigned_flag;
110
105
}
111
106
 
112
 
} /* namespace drizzled */