diff options
author | Ashish Agarwal <ashish.y.agarwal@oracle.com> | 2013-05-19 23:38:06 +0530 |
---|---|---|
committer | Ashish Agarwal <ashish.y.agarwal@oracle.com> | 2013-05-19 23:38:06 +0530 |
commit | 0c4f4ff015f7c4a06b9d4c9e8f22f44a57e2a318 (patch) | |
tree | 24753afbd8c14c24de460f691e8e4a67e50a32c8 /mysys | |
parent | 5ca36b3b46de00e9eb8030c0551e7e97bc8e24eb (diff) | |
download | mariadb-git-0c4f4ff015f7c4a06b9d4c9e8f22f44a57e2a318.tar.gz |
Bug#16194302: SUPPORT FOR FLOATING-POINT SYSTEM VARIABLES
USING THE PLUGIN INTERFACE.
ISSUE: No support for floating-point plugin
system variables.
SOLUTION: Allowing plugins to define and expose floating-point
system variables of type double. MYSQL_SYSVAR_DOUBLE
and MYSQL_THDVAR_DOUBLE are added.
ISSUE: Fractional part of the def, min, max values of system
variables are ignored.
SOLUTION: Adding functions that are used to store the raw
representation of a double in the raw bits of unsigned
longlong in a way that the binary representation
remains the same.
Diffstat (limited to 'mysys')
-rw-r--r-- | mysys/my_getopt.c | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index adee17ba3d1..8575fde0ca9 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -90,6 +90,35 @@ void my_getopt_register_get_addr(my_getopt_value func_addr) getopt_get_addr= func_addr; } +union ull_dbl +{ + ulonglong ull; + double dbl; +}; + +/** + Returns an ulonglong value containing a raw + representation of the given double value. +*/ +ulonglong getopt_double2ulonglong(double v) +{ + union ull_dbl u; + u.dbl= v; + compile_time_assert(sizeof(ulonglong) >= sizeof(double)); + return u.ull; +} + +/** + Returns the double value which corresponds to + the given raw representation. +*/ +double getopt_ulonglong2double(ulonglong v) +{ + union ull_dbl u; + u.ull= v; + return u.dbl; +} + /** Handle command line options. Sort options. @@ -1044,14 +1073,18 @@ double getopt_double_limit_value(double num, const struct my_option *optp, { my_bool adjusted= FALSE; double old= num; - if (optp->max_value && num > (double) optp->max_value) + double min, max; + + max= getopt_ulonglong2double(optp->max_value); + min= getopt_ulonglong2double(optp->min_value); + if (max && num > max) { - num= (double) optp->max_value; + num= max; adjusted= TRUE; } - if (num < (double) optp->min_value) + if (num < min) { - num= (double) optp->min_value; + num= min; adjusted= TRUE; } if (fix) @@ -1134,7 +1167,7 @@ static void init_one_value(const struct my_option *option, void *variable, *((ulonglong*) variable)= (ulonglong) value; break; case GET_DOUBLE: - *((double*) variable)= ulonglong2double(value); + *((double*) variable)= getopt_ulonglong2double(value); break; case GET_STR: /* |