cleanup: get_float convenience helper

more helpers like that can be added as needed
This commit is contained in:
Sergei Golubchik 2024-09-25 14:39:29 +02:00
parent 115d3e050c
commit 949fed514a
7 changed files with 16 additions and 21 deletions

View file

@ -16,6 +16,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
#include <string.h>
/* /*
Macro for reading 32-bit integer from network byte order (big-endian) Macro for reading 32-bit integer from network byte order (big-endian)
@ -51,4 +52,12 @@
#include "little_endian.h" #include "little_endian.h"
#endif #endif
/* convenienve helpers */
static inline float get_float(const void *from)
{
float to;
float4get(to, ((const uchar*)from));
return to;
}
#endif /* MY_BYTEORDER_INCLUDED */ #endif /* MY_BYTEORDER_INCLUDED */

View file

@ -3658,9 +3658,7 @@ static void fetch_result_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field,
} }
case MYSQL_TYPE_FLOAT: case MYSQL_TYPE_FLOAT:
{ {
float value; fetch_float_with_conversion(param, field, get_float(*row), MY_GCVT_ARG_FLOAT);
float4get(value,*row);
fetch_float_with_conversion(param, field, value, MY_GCVT_ARG_FLOAT);
*row+= 4; *row+= 4;
break; break;
} }

View file

@ -4862,16 +4862,12 @@ int Field_float::store(longlong nr, bool unsigned_val)
double Field_float::val_real(void) double Field_float::val_real(void)
{ {
DBUG_ASSERT(marked_for_read()); DBUG_ASSERT(marked_for_read());
float j; return ((double) get_float(ptr));
float4get(j,ptr);
return ((double) j);
} }
longlong Field_float::val_int(void) longlong Field_float::val_int(void)
{ {
float j; return Converter_double_to_longlong(get_float(ptr), false).result();
float4get(j,ptr);
return Converter_double_to_longlong(j, false).result();
} }

View file

@ -632,10 +632,8 @@ log_event_print_value(IO_CACHE *file, PRINT_EVENT_INFO *print_event_info,
if (!ptr) if (!ptr)
goto return_null; goto return_null;
float fl;
float4get(fl, ptr);
char tmp[320]; char tmp[320];
sprintf(tmp, "%-20g", (double) fl); sprintf(tmp, "%-20g", (double) get_float(ptr));
my_b_printf(file, "%s", tmp); /* my_snprintf doesn't support %-20g */ my_b_printf(file, "%s", tmp); /* my_snprintf doesn't support %-20g */
return 4; return 4;
} }

View file

@ -635,9 +635,7 @@ uint hp_rb_make_key(HP_KEYDEF *keydef, uchar *key,
if (seg->type == HA_KEYTYPE_FLOAT) if (seg->type == HA_KEYTYPE_FLOAT)
{ {
float nr; if (isnan(get_float(pos)))
float4get(nr, pos);
if (isnan(nr))
{ {
/* Replace NAN with zero */ /* Replace NAN with zero */
bzero(key, length); bzero(key, length);

View file

@ -284,9 +284,7 @@ MARIA_KEY *_ma_make_key(MARIA_HA *info, MARIA_KEY *int_key, uint keynr,
{ /* Numerical column */ { /* Numerical column */
if (type == HA_KEYTYPE_FLOAT) if (type == HA_KEYTYPE_FLOAT)
{ {
float nr; if (isnan(get_float(pos)))
float4get(nr,pos);
if (isnan(nr))
{ {
/* Replace NAN with zero */ /* Replace NAN with zero */
bzero(key,length); bzero(key,length);

View file

@ -158,9 +158,7 @@ uint _mi_make_key(register MI_INFO *info, uint keynr, uchar *key,
{ /* Numerical column */ { /* Numerical column */
if (type == HA_KEYTYPE_FLOAT) if (type == HA_KEYTYPE_FLOAT)
{ {
float nr; if (isnan(get_float(pos)))
float4get(nr,pos);
if (isnan(nr))
{ {
/* Replace NAN with zero */ /* Replace NAN with zero */
bzero(key,length); bzero(key,length);