~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/double.cc

  • Committer: Monty Taylor
  • Date: 2008-11-16 20:15:33 UTC
  • mto: (584.1.9 devel)
  • mto: This revision was merged to the branch mainline in revision 589.
  • Revision ID: monty@inaugust.com-20081116201533-d0f19s1bk1h95iyw
Removed a big bank of includes from item.h.

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
 
#include <drizzled/table.h>
32
 
#include <drizzled/session.h>
33
 
#include "drizzled/internal/m_string.h"
34
 
 
35
 
using namespace std;
36
 
 
37
 
namespace drizzled
38
 
{
 
25
#include CMATH_H
 
26
 
 
27
#if defined(CMATH_NAMESPACE)
 
28
using namespace CMATH_NAMESPACE;
 
29
#endif
39
30
 
40
31
/****************************************************************************
41
32
  double precision floating point numbers
46
37
  int error;
47
38
  char *end;
48
39
  double nr= my_strntod(cs,(char*) from, len, &end, &error);
49
 
 
50
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
51
 
  if (error || (!len || (((uint32_t) (end-from) != len) && table->in_use->count_cuted_fields)))
 
40
  if (error || (!len || (((uint) (end-from) != len) && table->in_use->count_cuted_fields)))
52
41
  {
53
42
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
54
43
                (error ? ER_WARN_DATA_OUT_OF_RANGE : ER_WARN_DATA_TRUNCATED), 1);
63
52
{
64
53
  int error= truncate(&nr, DBL_MAX);
65
54
 
66
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
67
 
 
68
55
#ifdef WORDS_BIGENDIAN
69
56
  if (table->s->db_low_byte_first)
70
57
  {
86
73
double Field_double::val_real(void)
87
74
{
88
75
  double j;
89
 
 
90
 
  ASSERT_COLUMN_MARKED_FOR_READ;
91
 
 
92
76
#ifdef WORDS_BIGENDIAN
93
77
  if (table->s->db_low_byte_first)
94
78
  {
104
88
{
105
89
  double j;
106
90
  int64_t res;
107
 
 
108
 
  ASSERT_COLUMN_MARKED_FOR_READ;
109
 
 
110
91
#ifdef WORDS_BIGENDIAN
111
92
  if (table->s->db_low_byte_first)
112
93
  {
132
113
  {
133
114
    char buf[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE];
134
115
    String tmp(buf, sizeof(buf), &my_charset_utf8_general_ci), *str;
135
 
    str= val_str(&tmp, &tmp);
 
116
    str= val_str(&tmp, 0);
136
117
    push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
137
118
                        ER_TRUNCATED_WRONG_VALUE,
138
119
                        ER(ER_TRUNCATED_WRONG_VALUE), "INTEGER",
143
124
 
144
125
 
145
126
String *Field_double::val_str(String *val_buffer,
146
 
                              String *)
 
127
                              String *val_ptr __attribute__((unused)))
147
128
{
148
129
  double nr;
149
 
 
150
 
  ASSERT_COLUMN_MARKED_FOR_READ;
151
 
 
152
130
#ifdef WORDS_BIGENDIAN
153
131
  if (table->s->db_low_byte_first)
154
132
  {
158
136
#endif
159
137
    doubleget(nr,ptr);
160
138
 
161
 
  uint32_t to_length= max(field_length, (uint32_t)DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE);
 
139
  uint32_t to_length=cmax(field_length, (uint32_t)DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE);
162
140
  val_buffer->alloc(to_length);
163
141
  char *to=(char*) val_buffer->ptr();
164
142
  size_t len;
165
143
 
166
144
  if (dec >= NOT_FIXED_DEC)
167
 
    len= internal::my_gcvt(nr, internal::MY_GCVT_ARG_DOUBLE, to_length - 1, to, NULL);
 
145
    len= my_gcvt(nr, MY_GCVT_ARG_DOUBLE, to_length - 1, to, NULL);
168
146
  else
169
 
    len= internal::my_fcvt(nr, dec, to, NULL);
 
147
    len= my_fcvt(nr, dec, to, NULL);
170
148
 
171
 
  val_buffer->length((uint32_t) len);
 
149
  val_buffer->length((uint) len);
172
150
 
173
151
  return val_buffer;
174
152
}
175
153
 
 
154
bool Field_double::send_binary(Protocol *protocol)
 
155
{
 
156
  return protocol->store((double) Field_double::val_real(), dec, (String*) 0);
 
157
}
 
158
 
 
159
 
176
160
int Field_double::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
177
161
{
178
162
  double a,b;
194
178
 
195
179
/* The following should work for IEEE */
196
180
 
197
 
void Field_double::sort_string(unsigned char *to,uint32_t )
 
181
void Field_double::sort_string(unsigned char *to,uint32_t length __attribute__((unused)))
198
182
{
199
183
  double nr;
200
184
#ifdef WORDS_BIGENDIAN
209
193
}
210
194
 
211
195
 
 
196
/**
 
197
   Save the field metadata for double fields.
 
198
 
 
199
   Saves the pack length in the first byte of the field metadata array
 
200
   at index of *metadata_ptr.
 
201
 
 
202
   @param   metadata_ptr   First byte of field metadata
 
203
 
 
204
   @returns number of bytes written to metadata_ptr
 
205
*/
 
206
int Field_double::do_save_field_metadata(unsigned char *metadata_ptr)
 
207
{
 
208
  *metadata_ptr= pack_length();
 
209
  return 1;
 
210
}
 
211
 
 
212
 
212
213
void Field_double::sql_type(String &res) const
213
214
{
214
215
  const CHARSET_INFO * const cs=res.charset();
223
224
  }
224
225
}
225
226
 
226
 
} /* namespace drizzled */