22 #include <drizzled/field/real.h>
23 #include <drizzled/error.h>
24 #include <drizzled/table.h>
34 extern const double log_10[309];
41 Field_real::pack(
unsigned char *to,
const unsigned char *from,
42 uint32_t max_length,
bool low_byte_first)
44 assert(max_length >= pack_length());
45 #ifdef WORDS_BIGENDIAN
46 if (low_byte_first != getTable()->getShare()->db_low_byte_first)
48 const unsigned char *dptr= from + pack_length();
55 return(Field::pack(to, from, max_length, low_byte_first));
59 Field_real::unpack(
unsigned char *to,
const unsigned char *from,
60 uint32_t param_data,
bool low_byte_first)
62 #ifdef WORDS_BIGENDIAN
63 if (low_byte_first != getTable()->getShare()->db_low_byte_first)
65 const unsigned char *dptr= from + pack_length();
68 return(from + pack_length());
72 return(Field::unpack(to, from, param_data, low_byte_first));
81 int Field_real::truncate(
double *nr,
double max_value)
86 if (res == numeric_limits<double>::quiet_NaN())
90 set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
96 uint32_t order= field_length - dec;
97 uint32_t step= array_elements(log_10) - 1;
99 for (; order > step; order-= step)
100 max_value*= log_10[step];
101 max_value*= log_10[order];
102 max_value-= 1.0 / log_10[dec];
105 if (res != numeric_limits<double>::infinity())
107 double tmp= rint((res - floor(res)) * log_10[dec]) / log_10[dec];
108 res= floor(res) + tmp;
112 if (res < -max_value)
115 set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
117 else if (res > max_value)
120 set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
134 class_decimal2double(E_DEC_FATAL_ERROR, dm, &dbl);
140 ASSERT_COLUMN_MARKED_FOR_READ;
142 double2_class_decimal(E_DEC_FATAL_ERROR, val_real(), decimal_value);
143 return decimal_value;
TODO: Rename this file - func.h is stupid.