~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/double.cc

  • Committer: Monty Taylor
  • Date: 2009-03-06 03:33:24 UTC
  • mfrom: (916.1.2 merge)
  • Revision ID: mordred@inaugust.com-20090306033324-dcedf80g9qzywbvu
Merged Brian's merge... re-rotate the tree.

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/internal/m_string.h"
34
 
 
35
 
using namespace std;
36
 
 
37
 
namespace drizzled
38
 
{
 
27
#include <drizzled/protocol.h>
 
28
 
 
29
#include CMATH_H
 
30
 
 
31
#if defined(CMATH_NAMESPACE)
 
32
using namespace CMATH_NAMESPACE;
 
33
#endif
39
34
 
40
35
/****************************************************************************
41
36
  double precision floating point numbers
46
41
  int error;
47
42
  char *end;
48
43
  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) && getTable()->in_use->count_cuted_fields)))
 
44
  if (error || (!len || (((uint32_t) (end-from) != len) && table->in_use->count_cuted_fields)))
52
45
  {
53
46
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
54
47
                (error ? ER_WARN_DATA_OUT_OF_RANGE : ER_WARN_DATA_TRUNCATED), 1);
63
56
{
64
57
  int error= truncate(&nr, DBL_MAX);
65
58
 
66
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
67
 
 
68
59
#ifdef WORDS_BIGENDIAN
69
 
  if (getTable()->getShare()->db_low_byte_first)
 
60
  if (table->s->db_low_byte_first)
70
61
  {
71
62
    float8store(ptr,nr);
72
63
  }
86
77
double Field_double::val_real(void)
87
78
{
88
79
  double j;
89
 
 
90
 
  ASSERT_COLUMN_MARKED_FOR_READ;
91
 
 
92
80
#ifdef WORDS_BIGENDIAN
93
 
  if (getTable()->getShare()->db_low_byte_first)
 
81
  if (table->s->db_low_byte_first)
94
82
  {
95
83
    float8get(j,ptr);
96
84
  }
104
92
{
105
93
  double j;
106
94
  int64_t res;
107
 
 
108
 
  ASSERT_COLUMN_MARKED_FOR_READ;
109
 
 
110
95
#ifdef WORDS_BIGENDIAN
111
 
  if (getTable()->getShare()->db_low_byte_first)
 
96
  if (table->s->db_low_byte_first)
112
97
  {
113
98
    float8get(j,ptr);
114
99
  }
146
131
                              String *)
147
132
{
148
133
  double nr;
149
 
 
150
 
  ASSERT_COLUMN_MARKED_FOR_READ;
151
 
 
152
134
#ifdef WORDS_BIGENDIAN
153
 
  if (getTable()->getShare()->db_low_byte_first)
 
135
  if (table->s->db_low_byte_first)
154
136
  {
155
137
    float8get(nr,ptr);
156
138
  }
158
140
#endif
159
141
    doubleget(nr,ptr);
160
142
 
161
 
  uint32_t to_length= max(field_length, (uint32_t)DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE);
 
143
  uint32_t to_length=cmax(field_length, (uint32_t)DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE);
162
144
  val_buffer->alloc(to_length);
163
145
  char *to=(char*) val_buffer->ptr();
164
146
  size_t len;
165
147
 
166
148
  if (dec >= NOT_FIXED_DEC)
167
 
    len= internal::my_gcvt(nr, internal::MY_GCVT_ARG_DOUBLE, to_length - 1, to, NULL);
 
149
    len= my_gcvt(nr, MY_GCVT_ARG_DOUBLE, to_length - 1, to, NULL);
168
150
  else
169
 
    len= internal::my_fcvt(nr, dec, to, NULL);
 
151
    len= my_fcvt(nr, dec, to, NULL);
170
152
 
171
153
  val_buffer->length((uint32_t) len);
172
154
 
177
159
{
178
160
  double a,b;
179
161
#ifdef WORDS_BIGENDIAN
180
 
  if (getTable()->getShare()->db_low_byte_first)
 
162
  if (table->s->db_low_byte_first)
181
163
  {
182
164
    float8get(a,a_ptr);
183
165
    float8get(b,b_ptr);
198
180
{
199
181
  double nr;
200
182
#ifdef WORDS_BIGENDIAN
201
 
  if (getTable()->getShare()->db_low_byte_first)
 
183
  if (table->s->db_low_byte_first)
202
184
  {
203
185
    float8get(nr,ptr);
204
186
  }
209
191
}
210
192
 
211
193
 
 
194
/**
 
195
   Save the field metadata for double fields.
 
196
 
 
197
   Saves the pack length in the first byte of the field metadata array
 
198
   at index of *metadata_ptr.
 
199
 
 
200
   @param   metadata_ptr   First byte of field metadata
 
201
 
 
202
   @returns number of bytes written to metadata_ptr
 
203
*/
 
204
int Field_double::do_save_field_metadata(unsigned char *metadata_ptr)
 
205
{
 
206
  *metadata_ptr= pack_length();
 
207
  return 1;
 
208
}
 
209
 
 
210
 
212
211
void Field_double::sql_type(String &res) const
213
212
{
214
213
  const CHARSET_INFO * const cs=res.charset();
223
222
  }
224
223
}
225
224
 
226
 
} /* namespace drizzled */