~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/real.cc

code clean move Item_func_num1 and Item_func_connection_id to functions directory

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include "config.h"
 
21
 
 
22
#include <drizzled/server_includes.h>
22
23
#include <drizzled/field/real.h>
23
 
#include <drizzled/error.h>
24
 
#include <drizzled/table.h>
25
 
 
26
 
#include <math.h>
27
 
 
28
 
#include <limits>
29
 
 
30
 
using namespace std;
31
 
 
32
 
namespace drizzled
33
 
{
34
 
 
35
 
extern const double log_10[309];
36
24
 
37
25
/*
38
26
  Floating-point numbers
44
32
{
45
33
  assert(max_length >= pack_length());
46
34
#ifdef WORDS_BIGENDIAN
47
 
  if (low_byte_first != getTable()->s->db_low_byte_first)
 
35
  if (low_byte_first != table->s->db_low_byte_first)
48
36
  {
49
37
    const unsigned char *dptr= from + pack_length();
50
38
    while (dptr-- > from)
61
49
                   uint32_t param_data, bool low_byte_first)
62
50
{
63
51
#ifdef WORDS_BIGENDIAN
64
 
  if (low_byte_first != getTable()->s->db_low_byte_first)
 
52
  if (low_byte_first != table->s->db_low_byte_first)
65
53
  {
66
54
    const unsigned char *dptr= from + pack_length();
67
55
    while (dptr-- > from)
83
71
{
84
72
  int error= 1;
85
73
  double res= *nr;
86
 
 
87
 
  if (res == numeric_limits<double>::quiet_NaN())
 
74
  
 
75
  if (std::isnan(res))
88
76
  {
89
77
    res= 0;
90
78
    set_null();
91
79
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
92
80
    goto end;
93
81
  }
 
82
  else if (unsigned_flag && res < 0)
 
83
  {
 
84
    res= 0;
 
85
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
 
86
    goto end;
 
87
  }
94
88
 
95
89
  if (!not_fixed)
96
90
  {
103
97
    max_value-= 1.0 / log_10[dec];
104
98
 
105
99
    /* Check for infinity so we don't get NaN in calculations */
106
 
    if (res != numeric_limits<double>::infinity())
 
100
    if (!(std::isinf(res)))
107
101
    {
108
102
      double tmp= rint((res - floor(res)) * log_10[dec]) / log_10[dec];
109
103
      res= floor(res) + tmp;
110
104
    }
111
105
  }
112
 
 
 
106
  
113
107
  if (res < -max_value)
114
108
  {
115
109
   res= -max_value;
138
132
 
139
133
my_decimal *Field_real::val_decimal(my_decimal *decimal_value)
140
134
{
141
 
  ASSERT_COLUMN_MARKED_FOR_READ;
142
 
 
143
135
  double2my_decimal(E_DEC_FATAL_ERROR, val_real(), decimal_value);
144
136
  return decimal_value;
145
137
}
146
 
 
147
 
} /* namespace drizzled */