2016-06-20 21:59 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)

* doc/cmpopt.txt
    * enumeration
    ! typos

  * src/codepage/uckam.c
    + added info about Kamenicky codepage number: CP895

  * include/hbapi.h
  * src/common/hbstr.c
    + added new C function:
         char * hb_dblToStr( char * szBuf, HB_SIZE nSize,
                             double dNumber, int iMaxDec );
      it converts numeric value to string trying to keep all significant
      digits in double numbers

  * include/harbour.hbx
  * src/rtl/hbntos.c
    + added new PRG function:
         hb_ntoc( <nValue> ) -> cValue
      it converts numeric value to string trying to keep all significant
      digits in double numbers

  * src/rtl/hbsocket.c
    + added support for error codes returned by
      getaddrinfo() / getnameinfo() and gethostbyname() / gethostbyaddr()

  * src/rtl/hbinet.c
    + set HB_SOCKET_ERR_WRONGADDR error code if hb_socketResolveAddr()
      returns NULL without setting error code

  * src/vm/arrays.c
  * src/vm/hashfunc.c
    ! fix hb_HScan(), AScan(), hb_AScan() and hb_RAScan() for very large
      integers with more then 53 significant bits. Such bits were lost
      after conversion to double value used in scan process

  * src/vm/itemapi.c
    * formatting

  * src/rtl/gtwvt/gtwvt.c
    ! do not convert characters received with ALTGR or ALT+CTRL flags to
      extended keycodes - some national keyboards may use such combination
      for national characters and even pure ASCII ones
This commit is contained in:
Przemysław Czerpak
2016-06-20 21:59:34 +02:00
parent 88fc3b1579
commit 6df7fc6132
13 changed files with 415 additions and 23 deletions

View File

@@ -819,6 +819,124 @@ char * hb_numToStr( char * szBuf, HB_SIZE nSize, HB_MAXINT lNumber )
return &szBuf[ iPos ];
}
/* if you want to be sure that size of buffer is enough to hold each
double number with '\0' terminating character then it should have
at least HB_MAX_DOUBLE_LENGTH bytes. If buffer is not large enough
then NULL is returned */
char * hb_dblToStr( char * szBuf, HB_SIZE nSize, double dNumber, int iMaxDec )
{
double dInt, dFract, dDig, doBase = 10.0;
int iLen, iPos, iPrec;
char * szResult;
HB_BOOL fFirst;
HB_TRACE( HB_TR_DEBUG, ( "hb_dblToStr(%p, %" HB_PFS "u, %f, %d)", szBuf, nSize, dNumber, iMaxDec ) );
iLen = ( int ) ( nSize - 1 );
if( iLen <= 0 )
return NULL;
#ifdef HB_NUM_PRECISION
iPrec = HB_NUM_PRECISION;
#else
iPrec = 16;
#endif
szResult = szBuf;
if( dNumber < 0 )
{
if( --iLen == 0 )
return NULL;
*szBuf++ = '-';
dFract = modf( -dNumber, &dInt );
}
else
dFract = modf( dNumber, &dInt );
iPos = iLen;
do
{
dDig = modf( dInt / doBase + 0.01, &dInt ) * doBase;
szBuf[ --iPos ] = '0' + ( char ) ( dDig + 0.01 );
if( iPos == 0 )
{
if( dInt >= 1 )
return NULL;
break;
}
}
while( dInt >= 1 );
if( iPos > 0 )
memmove( szBuf, szBuf + iPos, HB_MIN( iLen - iPos, iPrec ) );
iPos = iLen - iPos;
fFirst = iPos > 1 || szBuf[ 0 ] != '0';
if( fFirst )
{
if( iPos >= iPrec )
{
while( iPrec < iPos )
szBuf[ iPrec++ ] = '0';
iPrec = 0;
}
else
iPrec -= iPos;
}
while( dInt >= 1 )
{
if( iPos >= iLen )
return NULL;
dDig = modf( dInt / doBase + 0.01, &dInt ) * doBase;
szBuf[ iPos++ ] = iPrec-- > 0 ? '0' + ( char ) ( dDig + 0.01 ) : '0';
}
if( iPrec > 0 && iLen - iPos > 1 && iMaxDec != 0 && dFract > 0 )
{
int iDec = iPos;
szBuf[ iPos ] = '.';
while( ++iPos < iLen && iPrec > 0 && iMaxDec-- != 0 )
{
dFract = modf( dFract * doBase, &dDig );
szBuf[ iPos ] = '0' + ( char ) ( dDig + 0.01 );
if( szBuf[ iPos ] != '0' )
fFirst = HB_TRUE;
if( fFirst )
--iPrec;
}
if( dFract > ( iPrec > 0 ? 0.5 - hb_numPow10( -iPrec ) : 0.2 ) )
{
iPrec = iPos;
for( ;; )
{
if( --iPrec < 0 )
{
memmove( szBuf + 1, szBuf, iPos );
*szBuf = '1';
if( iPos < iLen )
++iPos;
++iDec;
break;
}
if( iPrec == iDec )
--iPrec;
if( szBuf[ iPrec ] != '9' )
{
++szBuf[ iPrec ];
break;
}
szBuf[ iPrec ] = '0';
}
}
while( iPos > iDec && szBuf[ iPos - 1 ] == '0' )
--iPos;
if( szBuf[ iPos - 1 ] == '.' )
--iPos;
}
szBuf[ iPos ] = '\0';
return iPos == 1 && *szResult == '-' && *szBuf == '0' ? szBuf : szResult;
}
/*
* This function copies szText to destination buffer.
* NOTE: Unlike the documentation for strncpy, this routine will always append