~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/double.cc

  • Committer: Brian Aker
  • Date: 2008-10-07 15:13:28 UTC
  • mfrom: (481.1.19 codestyle)
  • Revision ID: brian@tangent.org-20081007151328-m49yev7qggqmzxg1
Mergining Monty's work

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
                             (double) nr);
69
69
}
70
70
 
71
 
/*
72
 
  If a field has fixed length, truncate the double argument pointed to by 'nr'
73
 
  appropriately.
74
 
  Also ensure that the argument is within [-max_value; max_value] range.
75
 
*/
76
 
 
77
 
int Field_real::truncate(double *nr, double max_value)
78
 
{
79
 
  int error= 1;
80
 
  double res= *nr;
81
 
  
82
 
  if (isnan(res))
83
 
  {
84
 
    res= 0;
85
 
    set_null();
86
 
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
87
 
    goto end;
88
 
  }
89
 
  else if (unsigned_flag && res < 0)
90
 
  {
91
 
    res= 0;
92
 
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
93
 
    goto end;
94
 
  }
95
 
 
96
 
  if (!not_fixed)
97
 
  {
98
 
    uint32_t order= field_length - dec;
99
 
    uint32_t step= array_elements(log_10) - 1;
100
 
    max_value= 1.0;
101
 
    for (; order > step; order-= step)
102
 
      max_value*= log_10[step];
103
 
    max_value*= log_10[order];
104
 
    max_value-= 1.0 / log_10[dec];
105
 
 
106
 
    /* Check for infinity so we don't get NaN in calculations */
107
 
    if (!isinf(res))
108
 
    {
109
 
      double tmp= rint((res - floor(res)) * log_10[dec]) / log_10[dec];
110
 
      res= floor(res) + tmp;
111
 
    }
112
 
  }
113
 
  
114
 
  if (res < -max_value)
115
 
  {
116
 
   res= -max_value;
117
 
   set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
118
 
  }
119
 
  else if (res > max_value)
120
 
  {
121
 
    res= max_value;
122
 
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
123
 
  }
124
 
  else
125
 
    error= 0;
126
 
 
127
 
end:
128
 
  *nr= res;
129
 
  return error;
130
 
}
131
 
 
132
 
 
133
 
int Field_real::store_decimal(const my_decimal *dm)
134
 
{
135
 
  double dbl;
136
 
  my_decimal2double(E_DEC_FATAL_ERROR, dm, &dbl);
137
 
  return store(dbl);
138
 
}
139
 
 
140
71
double Field_double::val_real(void)
141
72
{
142
73
  double j;
190
121
}
191
122
 
192
123
 
193
 
my_decimal *Field_real::val_decimal(my_decimal *decimal_value)
194
 
{
195
 
  double2my_decimal(E_DEC_FATAL_ERROR, val_real(), decimal_value);
196
 
  return decimal_value;
197
 
}
198
 
 
199
 
 
200
124
String *Field_double::val_str(String *val_buffer,
201
125
                              String *val_ptr __attribute__((unused)))
202
126
{