diff options
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: /* |