Hi
here is the piece of code I'm talking about
Code:
float bytes2float(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
{
int i;
char *cbuf = args->args[0];
for ( i=0; i<4; i++){
fprintf(stderr,"cbuf[%d] = %d\n", i, cbuf[i]);
}
if ( !is_bigendian() ){
ReverseArray(args->args[0]);
};
for ( i=0; i<4; i++){
fprintf(stderr,"cbuf[%d] = %d\n", i, cbuf[i]);
}
float *fp = (float *) cbuf;
//printf("*fp = %3.3f\n\n", *fp);
fprintf(stderr,"return is %3.5f\n",*fp);
return *fp;
}
It is inserted in the db
CREATE FUNCTION bytes2float RETURNS REAL SONAME 'bytes2float.so';
Normally this piece of code is called within a stored procedure, but I also tried it in the mysql commandline interface
SELECT bytes2float( 'AK33'[) which are the bytes for float 12.70
You can see in one of the last lines that I print the calculated value to the errorlogflie and that gives me '12.70' and that is correct, but mysql is returning 5.41222900980635e-315
I am working with a complete 64 bits ubuntu linux version.
I tried this code also on my laptop with version 5.0 but then the 32 bits version and there the returnvalue is correct.
Regards Kees