FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para CA-Clipper nDbl2Flt()
Posts: 166
Joined: Mon Dec 12, 2005 09:56 AM
nDbl2Flt()
Posted: Fri Feb 17, 2006 05:39 PM

Hola a todos.

Sigo intentando pasar una aplicaci贸n de FW 2.4 a FW 2.7, y estoy a punto de tirar la toalla (No quiero pensar que pasar谩 cuando intente pasarla a 32 bits :( ). Ahora me ocurre que al mostrar unos controles char2fx me da el siguiente error:

Floating Point: Stack Underflow

El problema es en una l铆nea donde tengo que pasar un valor float al control VBX: oChart1:Adm[2] := ndbl2flt(nmaximo1).

A pesar de haber mirado las modificaciones hechas en FW desde la versi贸n 2.4, no aparece nada relativo a ning煤n cambio en la funci贸n ndbl2flt(), sin embargo si hay un "ligeris铆mo" cambio, en la versi贸n FW 2.7 hay una l铆nea que pone:

if ( d == 0 )
return 0;

L铆nea que no figura en la versi贸n 2.4

Creo que el problema puede ser ese, aunque no controlo C, entiendo que con esa l铆nea a帽adida el tipo que devuelve no es float cuando el valor es 0, con lo cual el control VBX me da un error, cuando con la versi贸n 2.4 no suced铆a.

Me imagino que la soluci贸n es compilar el fichero dbl2flt.c de FW 2.4 e incluir el OBJ en mi fichero LNK. Si esa es la soluci贸n, la pregunta del mill贸n, que hace tiempo conoc铆a y ya se me ha olvidado: 驴 Como compilo ese fichero ?

Saludos

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
nDbl2Flt()
Posted: Fri Feb 17, 2006 09:34 PM

Sebasti谩n,

Incluimos ese peque帽o cambio por recomendaci贸n de Enrico y supusimos que no dar铆a ning煤n problema.

Aqui puedes descargar el OBJ corregido:

http://hyperupload.com/download/d5c7402 ... T.OBJ.html

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
nDbl2Flt()
Posted: Fri Feb 17, 2006 10:32 PM

Antonio, just try this:

? NDBL2FLT( 0 )

With

if ( d == 0 ) return 0;

you will get, correctly, 0 while without the above if you will get

1073741824

that is clearly a wrong result (and caused wrong results in one of my programs, that is why I made that change).

EMG

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
nDbl2Flt()
Posted: Fri Feb 17, 2006 10:39 PM

And speaking of nDbl2Flt(), I just noticed that it is not in the libraries but only in source code. Why?

EMG

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
nDbl2Flt()
Posted: Fri Feb 17, 2006 11:48 PM

Sebastian,

Funciona bien ahora ?

Enrico,

Lets see Sebastian's results. Anyhow I am going to review it. Thanks my friend.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
nDbl2Flt()
Posted: Sat Feb 18, 2006 12:52 PM
EnricoMaria wrote:And speaking of nDbl2Flt(), I just noticed that it is not in the libraries but only in source code. Why?

EMG


I ask myself, how could have Sebastian tried nDbl2Flt() if it is not in the libraries? Did you compile the source code?

EMG
Posts: 166
Joined: Mon Dec 12, 2005 09:56 AM
nDbl2Flt()
Posted: Mon Feb 20, 2006 09:04 AM

Hola Antonio.

No, la versi贸n de dbl2flt.obj que he descargado de ese sitio tampoco funciona, me da el mismo error.

Lo he solucionado sacando DBL2FLT.OBJ de la librer铆a FIVEC.LIB de la versi贸n 2.4 y a帽adiendolo a mi LNK.

Saludos

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
nDbl2Flt()
Posted: Mon Feb 20, 2006 10:01 AM

Sebasti谩n,

Cierto, ese m贸dulo hay que compilarlo con Microsoft en 16 bits, no con Borland. De ah铆 el error. Disculpa.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
nDbl2Flt()
Posted: Mon Feb 20, 2006 10:13 AM

Enrico,

My mistake, that module needs to be compiled with Microsoft 16 bits for FW Clipper.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
nDbl2Flt()
Posted: Mon Feb 20, 2006 11:02 AM
Antonio Linares wrote:Enrico,

My mistake, that module needs to be compiled with Microsoft 16 bits for FW Clipper.


No! I compiled mine with Borland and worked fine. This is my DBL2FLT.C:

/***************************************************************************
*
*  Copyright 1995 Feh鈥歳 Attila alias White Wolf. All rights reserved.
*
*  This is original work of Feh鈥歳 Attila (alias White Wolf).
*
*  This code allowed to use for Mr. Antonio Linares for his FiveWin
*  project. Any other use must be discussed with the author (for the moment).
*
*  MUST BE COMPILED WITH MSC!!
*  BC can't handle the double correctly in MSC environment like Clipper.
*
*
*  Final version will be done in assembly w/o Clipper callable part.
*
***************************************************************************/

#include <HbApi.h>

long dbl2flt( double x );

HB_FUNC( NDBL2FLT )
{
   hb_retnl( dbl2flt( hb_parnd( 1 ) ) );
}

long dbl2flt( double d )
{
   long f = 0;
   int ui;
   char sig;

   if ( d == 0 ) return 0;

   sig = ( char )( ( ( char * )( &d ) )[7] & 0x80 );   // Store signum

   ( char )( ( ( char * )( &d ) )[7]) &= 0x7f;         // Get rid of signum

   ui = ( ( short * )( &d ) )[3] & 0xfff0;             // Get exponent

   ui = ui / 16 - 1023 + 127;

   ( ( char * )( &f ) )[3] = ( char ) ui;              // Put exponent

   ( ( char * )( &f ) )[2] |= ( char )( ( ( ( char * )( &d ) )[6] ) << 4 );              // Mantissa 1
   ( ( char * )( &f ) )[2] |= ( char )( ( ( ( ( char * )( &d ) )[5] ) >> 4 ) & 0x0f );   // Mantissa 2
   ( ( char * )( &f ) )[1] |= ( char )( ( ( ( char * )( &d ) )[5] ) << 4 );              // Mantissa 3
   ( ( char * )( &f ) )[1] |= ( char )( ( ( ( ( char * )( &d ) )[4] ) >> 4 ) & 0x0f );   // Mantissa 4
   ( ( char * )( &f ) )[0] |= ( char )( ( ( ( char * )( &d ) )[4] ) << 4 );              // Mantissa 5
   ( ( char * )( &f ) )[0] |= ( char )( ( ( ( ( char * )( &d ) )[3] ) >> 4 ) & 0x0f );   // Mantissa 6

   f >>= 1; ( ( char * )( &f ) )[3] &= 0x7f;   // Clear signum "C error!!!"
   ( ( char * )( &f ) )[3] |= sig;             // Add signum

   return f;
}


EMG
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
nDbl2Flt()
Posted: Mon Feb 20, 2006 11:04 AM

Ops, sorry. I suddenly understand that this is a FW for Clipper forum. :-)

EMG

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
nDbl2Flt()
Posted: Mon Feb 20, 2006 03:28 PM

Enrico,

No problem :) Yes, its 16 bits code.

regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion