~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/functions/mod.cc

  • Committer: Stewart Smith
  • Date: 2008-10-15 04:21:24 UTC
  • mto: This revision was merged to the branch mainline in revision 516.
  • Revision ID: stewart@flamingspork.com-20081015042124-kdmb74bcbky1k1nz
remove my_pthread_[gs]etspecific

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