mysql精度

fix_num_length_and_dec:
void Item_func::fix_num_length_and_dec()
{
uint fl_length= 0;
decimals=0;
for (uint i=0 ; i < arg_count ; i++)
{
set_if_bigger(decimals,args[i]->decimals);
set_if_bigger(fl_length, args[i]->max_length);
}
max_length=float_length(decimals);
if (fl_length > max_length)
{
decimals= NOT_FIXED_DEC;
max_length= float_length(NOT_FIXED_DEC);
}
}

void Item_func_numhybrid::fix_num_length_and_dec()
{}

fix_length_and_dec:

void Item_func_numhybrid::fix_length_and_dec()
{
fix_num_length_and_dec();
find_num_type();
}

void Item_func_minus::fix_length_and_dec()
{
Item_num_op::fix_length_and_dec();
if (unsigned_flag &&
(current_thd->variables.sql_mode & MODE_NO_UNSIGNED_SUBTRACTION))
unsigned_flag=0;
}

void Item_func_div::fix_length_and_dec()
{
DBUG_ENTER(“Item_func_div::fix_length_and_dec”);
prec_increment= current_thd->variables.div_precincrement;
Item_num_op::fix_length_and_dec();
switch(hybrid_type) {
case REAL_RESULT:
{
decimals=max(args[0]->decimals,args[1]->decimals)+prec_increment;
set_if_smaller(decimals, NOT_FIXED_DEC);
uint tmp=float_length(decimals);
if (decimals == NOT_FIXED_DEC)
max_length= tmp;
else
{
max_length=args[0]->max_length - args[0]->decimals + decimals;
set_if_smaller(max_length,tmp);
}
break;
}
case INT_RESULT:
hybrid_type= DECIMAL_RESULT;
DBUG_PRINT(“info”, (“Type changed: DECIMAL_RESULT”));
result_precision();
break;
case DECIMAL_RESULT:
result_precision();
break;
default:
DBUG_ASSERT(0);
}
maybe_null= 1; // devision by zero
DBUG_VOID_RETURN;
}

void Item_func_mod::fix_length_and_dec()
{
Item_num_op::fix_length_and_dec();
maybe_null= 1;
unsigned_flag= args[0]->unsigned_flag;
}

result_precision:
/**
Set precision of results for additive operations (+ and -)
*/
void Item_func_additive_op::result_precision()
{
decimals= max(args[0]->decimals, args[1]->decimals);
int arg1_int= args[0]->decimal_precision() - args[0]->decimals;
int arg2_int= args[1]->decimal_precision() - args[1]->decimals;
int precision= max(arg1_int, arg2_int) + 1 + decimals;

/* Integer operations keep unsigned_flag if one of arguments is unsigned */
if (result_type() == INT_RESULT)
unsigned_flag= args[0]->unsigned_flag | args[1]->unsigned_flag;
else
unsigned_flag= args[0]->unsigned_flag & args[1]->unsigned_flag;
max_length= my_decimal_precision_to_length_no_truncation(precision, decimals,
unsigned_flag);
}

void Item_func_mul::result_precision()
{
/* Integer operations keep unsigned_flag if one of arguments is unsigned */
if (result_type() == INT_RESULT)
unsigned_flag= args[0]->unsigned_flag | args[1]->unsigned_flag;
else
unsigned_flag= args[0]->unsigned_flag & args[1]->unsigned_flag;
decimals= min(args[0]->decimals + args[1]->decimals, DECIMAL_MAX_SCALE);
uint est_prec = args[0]->decimal_precision() + args[1]->decimal_precision();
uint precision= min(est_prec, DECIMAL_MAX_PRECISION);
max_length= my_decimal_precision_to_length_no_truncation(precision, decimals,
unsigned_flag);
}

void Item_func_div::result_precision()
{
uint precision= min(args[0]->decimal_precision() +
args[1]->decimals + prec_increment,
DECIMAL_MAX_PRECISION);

/* Integer operations keep unsigned_flag if one of arguments is unsigned */
if (result_type() == INT_RESULT)
unsigned_flag= args[0]->unsigned_flag | args[1]->unsigned_flag;
else
unsigned_flag= args[0]->unsigned_flag & args[1]->unsigned_flag;
decimals= min(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE);
max_length= my_decimal_precision_to_length_no_truncation(precision, decimals,
unsigned_flag);
}

void Item_func_mod::result_precision()
{
decimals= max(args[0]->decimals, args[1]->decimals);
max_length= max(args[0]->max_length, args[1]->max_length);
}

你可能感兴趣的:(mysql)