~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/double.cc

  • Committer: Monty Taylor
  • Date: 2009-03-08 23:45:12 UTC
  • mto: (923.2.1 mordred)
  • mto: This revision was merged to the branch mainline in revision 921.
  • Revision ID: mordred@inaugust.com-20090308234512-tqkygxtu1iaig23s
Removed C99 isnan() usage, which allows us to remove the util/math.{cc,h} workarounds. Yay for standards!

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
 
22
 
#include <config.h>
23
 
 
24
 
#include <float.h>
25
 
#include <math.h>
26
 
 
27
 
#include <algorithm>
28
 
 
 
22
#include <drizzled/server_includes.h>
29
23
#include <drizzled/field/double.h>
30
24
#include <drizzled/error.h>
31
25
#include <drizzled/table.h>
32
26
#include <drizzled/session.h>
33
 
#include <drizzled/current_session.h>
34
 
#include <drizzled/internal/m_string.h>
35
 
 
36
 
using namespace std;
37
 
 
38
 
namespace drizzled
39
 
{
 
27
#include <drizzled/protocol.h>
 
28
 
40
29
 
41
30
/****************************************************************************
42
31
  double precision floating point numbers
47
36
  int error;
48
37
  char *end;
49
38
  double nr= my_strntod(cs,(char*) from, len, &end, &error);
50
 
 
51
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
52
 
  if (error || (!len || (((uint32_t) (end-from) != len) && getTable()->in_use->count_cuted_fields)))
 
39
  if (error || (!len || (((uint32_t) (end-from) != len) && table->in_use->count_cuted_fields)))
53
40
  {
54
41
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
55
42
                (error ? ER_WARN_DATA_OUT_OF_RANGE : ER_WARN_DATA_TRUNCATED), 1);
64
51
{
65
52
  int error= truncate(&nr, DBL_MAX);
66
53
 
67
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
68
 
 
69
54
#ifdef WORDS_BIGENDIAN
70
 
  if (getTable()->getShare()->db_low_byte_first)
 
55
  if (table->s->db_low_byte_first)
71
56
  {
72
57
    float8store(ptr,nr);
73
58
  }
84
69
                             (double) nr);
85
70
}
86
71
 
87
 
double Field_double::val_real(void) const
 
72
double Field_double::val_real(void)
88
73
{
89
74
  double j;
90
 
 
91
 
  ASSERT_COLUMN_MARKED_FOR_READ;
92
 
 
93
75
#ifdef WORDS_BIGENDIAN
94
 
  if (getTable()->getShare()->db_low_byte_first)
 
76
  if (table->s->db_low_byte_first)
95
77
  {
96
78
    float8get(j,ptr);
97
79
  }
101
83
  return j;
102
84
}
103
85
 
104
 
int64_t Field_double::val_int(void) const
 
86
int64_t Field_double::val_int(void)
105
87
{
106
88
  double j;
107
89
  int64_t res;
108
 
 
109
 
  ASSERT_COLUMN_MARKED_FOR_READ;
110
 
 
111
90
#ifdef WORDS_BIGENDIAN
112
 
  if (getTable()->getShare()->db_low_byte_first)
 
91
  if (table->s->db_low_byte_first)
113
92
  {
114
93
    float8get(j,ptr);
115
94
  }
134
113
    char buf[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE];
135
114
    String tmp(buf, sizeof(buf), &my_charset_utf8_general_ci), *str;
136
115
    str= val_str(&tmp, &tmp);
137
 
    Session *session= getTable() ? getTable()->in_use : current_session;
138
 
    push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
116
    push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
139
117
                        ER_TRUNCATED_WRONG_VALUE,
140
118
                        ER(ER_TRUNCATED_WRONG_VALUE), "INTEGER",
141
119
                        str->c_ptr());
144
122
}
145
123
 
146
124
 
147
 
String *Field_double::val_str(String *val_buffer, String *) const
 
125
String *Field_double::val_str(String *val_buffer,
 
126
                              String *)
148
127
{
149
128
  double nr;
150
 
 
151
 
  ASSERT_COLUMN_MARKED_FOR_READ;
152
 
 
153
129
#ifdef WORDS_BIGENDIAN
154
 
  if (getTable()->getShare()->db_low_byte_first)
 
130
  if (table->s->db_low_byte_first)
155
131
  {
156
132
    float8get(nr,ptr);
157
133
  }
159
135
#endif
160
136
    doubleget(nr,ptr);
161
137
 
162
 
  uint32_t to_length= max(field_length, (uint32_t)DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE);
 
138
  uint32_t to_length=cmax(field_length, (uint32_t)DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE);
163
139
  val_buffer->alloc(to_length);
164
140
  char *to=(char*) val_buffer->ptr();
165
141
  size_t len;
166
142
 
167
143
  if (dec >= NOT_FIXED_DEC)
168
 
    len= internal::my_gcvt(nr, internal::MY_GCVT_ARG_DOUBLE, to_length - 1, to, NULL);
 
144
    len= my_gcvt(nr, MY_GCVT_ARG_DOUBLE, to_length - 1, to, NULL);
169
145
  else
170
 
    len= internal::my_fcvt(nr, dec, to, NULL);
 
146
    len= my_fcvt(nr, dec, to, NULL);
171
147
 
172
148
  val_buffer->length((uint32_t) len);
173
149
 
178
154
{
179
155
  double a,b;
180
156
#ifdef WORDS_BIGENDIAN
181
 
  if (getTable()->getShare()->db_low_byte_first)
 
157
  if (table->s->db_low_byte_first)
182
158
  {
183
159
    float8get(a,a_ptr);
184
160
    float8get(b,b_ptr);
199
175
{
200
176
  double nr;
201
177
#ifdef WORDS_BIGENDIAN
202
 
  if (getTable()->getShare()->db_low_byte_first)
 
178
  if (table->s->db_low_byte_first)
203
179
  {
204
180
    float8get(nr,ptr);
205
181
  }
210
186
}
211
187
 
212
188
 
 
189
/**
 
190
   Save the field metadata for double fields.
 
191
 
 
192
   Saves the pack length in the first byte of the field metadata array
 
193
   at index of *metadata_ptr.
 
194
 
 
195
   @param   metadata_ptr   First byte of field metadata
 
196
 
 
197
   @returns number of bytes written to metadata_ptr
 
198
*/
 
199
int Field_double::do_save_field_metadata(unsigned char *metadata_ptr)
 
200
{
 
201
  *metadata_ptr= pack_length();
 
202
  return 1;
 
203
}
 
204
 
 
205
 
213
206
void Field_double::sql_type(String &res) const
214
207
{
215
208
  const CHARSET_INFO * const cs=res.charset();
224
217
  }
225
218
}
226
219
 
227
 
} /* namespace drizzled */