nDbl2Flt()

Post Reply
User avatar
Sebastián Almirón
Posts: 125
Joined: Mon Dec 12, 2005 9:56 am
Location: Moralzarzal - Spain

nDbl2Flt()

Post by Sebastián Almirón »

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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

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
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

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
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

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

EMG
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

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
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

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
User avatar
Sebastián Almirón
Posts: 125
Joined: Mon Dec 12, 2005 9:56 am
Location: Moralzarzal - Spain

Post by Sebastián Almirón »

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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Enrico,

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

Antonio Linares
www.fivetechsoft.com
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

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:

Code: Select all

/***************************************************************************
*
*  Copyright 1995 Feh‚r Attila alias White Wolf. All rights reserved.
*
*  This is original work of Feh‚r 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
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

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

EMG
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Enrico,

No problem :) Yes, its 16 bits code.
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply