Tiene FW alguna funcion para pasar un signed float (double 8 bytes) a binario, de forma similar a como lo hace W2BIN() con los signed integer de 2 bytes??
Harbour no la tiene.
Gracias!!
HB_FUNC( F2BIN )
{
char szString[ 4 ];
if( ISNUM( 1 ) )
{
float fValue = ( float ) hb_parnd( 1 );
szString[ 0 ] = ( fValue & 0x00FF );
szString[ 1 ] = ( fValue & 0xFF00 ) >> 8;
szString[ 2 ] = ( fValue & 0x00FF0000 ) >> 16;
szString[ 3 ] = ( fValue & 0xFF000000 ) >> 24;
}
else
{
szString[ 0 ] = '\0';
}
hb_retclen( szString, 4 );
}Antonio he intentado compilar y me da 4 errores:
Error E2060 prueba.prg 10: Illegal use of floating point in function HB_FUN_F2BIN.
Error E2060 prueba.prg 11: Illegal use of floating point in function HB_FUN_F2BIN.
Error E2060 prueba.prg 12: Illegal use of floating point in function HB_FUN_F2BIN.
Error E2060 prueba.prg 13: Illegal use of floating point in function HB_FUN_F2BIN.
Correspondientes a cada asignaci贸n en el array szString
Estoy compilando con Borland C++ 5.51 y Harbour Alpha 45.0
Cambia estas cuatro l铆neas:
szString[ 0 ] = * ( char * ) &fValue;
szString[ 1 ] = * ( ( char * ) &fValue + 1 );
szString[ 2 ] = * ( ( char * ) &fValue + 2 );
szString[ 3 ] = * ( ( char * ) &fValue + 3 );
HB_FUNC( F2BIN )
{
float fValue = hb_parnd( 1 );
hb_retclen( ( char * ) &fValue, 4 );
}Antonio,
Ahora si parece funcionar pero necesito que devuelva un float con signo de doble presici贸n o sea 8 bytes no 4.
Hay alguna manera de incluir esta funci贸n en un .hrb? al compilar y ejecutar si me reconoce la funci贸n f2bin() pero si intento ejecutarlo con hbrun me falla me dice que no conoce o no esta registrado el s铆mbolo f2bin.
Antonio he probado con
HB_FUNC( D2BIN )
{
double fValue = hb_parnd( 1 );
hb_retclen( ( char * ) &fValue, 8 );
}
Y funciona correctamente, s贸lo me queda saber c贸mo se podr铆a utilizar con hbrun
Al construir hbrun tienes que incluir esta nueva funci贸n
Muchas gracias Antonio.