On Wed, 28 Jan 2009, Xavi wrote: Hi Xavi,
> The return value does not include the terminating null byte in the count. > ... > if( c != 0 ) ++size; > } > while( c != 0 ); > ... I cannot find such code in hbprintf.c. hb_printf_c() for sure sets trailing \0 byte in all cases even if buffer is too small. > I made a few tests with BCC and Spd add #define snprintf hb_snprintf_c > and the basics are working but with differences in accuracy. > ? Sql_sprintf( "Phi = %.15f", (1 + 5**0.5) / 2 ) ) > Phi = 1.618033988749895 snprintf() it's Ok > Phi = 1.618033981323242 hb_snprintf_c() Welcome to the fantastic world of floating point arithmetic by Borland. Try this code with this "incredible" compiler: #include <stdio.h> #include <math.h> #include <float.h> int main( void ) { printf( "[%.15f]\n", ((1 + pow(5.0,0.5)) / 2 ) ); _fpclass( 0 ); printf( "[%.15f]\n", ((1 + pow(5.0,0.5)) / 2 ) ); return 0; } It's good to know that calling _fpclass() reduce floating point precision to 'float' type even if you use 'double' or 'long double'. It will create problems for us also in HVM calculations if 3-r party code execute this function, f.e. try this: proc main() ? str( (1 + 5**0.5) / 2, 20, 15 ) _fpclass() ? str( (1 + 5**0.5) / 2, 20, 15 ) return #pragma begindump #include <math.h> #include <float.h> HB_FUNC( _FPCLASS ) { _fpclass( 0 ); } #pragma enddump I'll disable _fplcass() and checking for +-inf in BCC builds. It will fix the results and I think we should document it somewhere to avoid possible problems which can be created by 3-r party code which will try to use it. _fplcass() is forbidden in BCC builds !!!! ;-) ============================================== best regards, Przemek _______________________________________________ Harbour mailing list Harbour@harbour-project.org http://lists.harbour-project.org/mailman/listinfo/harbour