~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Monty Taylor
  • Date: 2008-12-18 07:24:54 UTC
  • mto: This revision was merged to the branch mainline in revision 714.
  • Revision ID: monty@bitters-20081218072454-8pnep622damjgqli
Fixed one more my_time thing.

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