Issue Details (XML | Word | Printable)

Key: CORE-1171
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Claudio Valderrama C.
Reporter: Bill Oliver
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Firebird Core

isql exponential format of numbers has zero pad on windows

Created: 16/Mar/07 03:17 PM   Updated: 24/May/11 11:17 AM
Component/s: ISQL
Affects Version/s: 0.9, 0.9.4, 0.9.5, 1.0 RC1, 1.0 RC2, 1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.5 Alpha 3, 1.5 Alpha 4, 1.5 Alpha 5, 1.5 Beta 1, 1.5 Beta 2, 1.5 Beta 3, 1.5 Beta 4, 1.5 RC1, 1.5 RC2, 1.5 RC3, 1.5 RC4, 1.5 RC5, 1.5 RC6, 1.5 RC7, 1.5 RC8, 1.5 RC9, 1.5.0, 1.5.1, 1.5.2, 1.5.3, 2.0 Beta 1, 2.0 RC1, 2.0 Beta 2, 2.0 RC2, 2.0 RC3, 2.0 RC4, 2.0 RC5, 2.0.0, 1.5.4
Fix Version/s: 2.5 Beta 2, 2.1.3

Time Tracking:
Not Specified

Environment: windows
Issue Links:
Relate
 


 Description  « Hide
Entering a tracker, as this might be a useful snippet to add to Firebird 2+.

Exponential formatting of numbers is different between Windows and Unix for 2-digit exponents. On Windows there is a zero pad, so that the exponent is always 3 digits. For example:

select cast ('-2.488355210669293e+39' as double precision) from rdb$database;

On Unix you get
 -2.488355210669293e+39

On Windows you get
 -2.488355210669293e+039

With the Microsoft and Intel compilers, the default behavior is to zero pad. This differs on Unix.

It would be nice to to have the zero pad removed on Windows. This would make managing differences between hosts easier. Tom has fixed this in ISQL with the following code:


#if defined(SAS_FIREBIRD) && defined(SSA_OS_WIN)
void unix_exponent_formatting(char * p) {

/* Find the exponent part of the formatted value */
char *exp_p = strpbrk(p+1, "eE");

/* If there is one and the next byte is a zero... */
if( exp_p )
           if((exp_p[1] == '+' || exp_p[1] == '-') && exp_p[2] == '0')
{
/*
                 * We want to shift everything right one character to munch
                 * the leading '0' of the exponent.
                 */
for( char * px = exp_p+2; px > p; px-- )
*px = *(px-1);
*p = ' ';
}
}
#define UNIX_EXPONENT_FORMATTING( x ) unix_exponent_formatting( x );
#else
#define UNIX_EXPONENT_FORMATTING( x )
#endif

and this is called from print_item() for types of SQL_FLOAT and SQL_DOUBLE:

case SQL_FLOAT:
sprintf(p, "% #*.*g ",
(int) length,
(int) MIN(8, (length - 6)),
(double) *(float *) (var->sqldata));
UNIX_EXPONENT_FORMATTING( p )

if (List) {
sprintf(Print_buffer, "%.*g%s",
FLOAT_LEN - 6, *(float *) (var->sqldata), NEWLINE);
UNIX_EXPONENT_FORMATTING( Print_buffer )

ISQL_printf(Out, Print_buffer);
}
break;

case SQL_DOUBLE:
/* Don't let numeric/decimal doubles overflow print length */
/* Special handling for 0 -- don't test log for length */
d_value = *(double*)(var->sqldata);
if (d_value != 0.0)
d_width = log10(fabs(d_value));

if ((d_width == 0 && dscale) ||
                            (dscale && (d_width+dscale < length ))) {
sprintf(p, "%*.*f ", (int) length, (int) -dscale,
*(double *) (var->sqldata));

if (List) {
sprintf(Print_buffer, "%.*f%s",
(int) -dscale,
*(double *) (var->sqldata), NEWLINE);
ISQL_printf(Out, Print_buffer);
}
}
else {
sprintf(p, "% #*.*g ", (int) length,
(int) MIN(16, (int) (length - 7)),
*(double *) (var->sqldata));
UNIX_EXPONENT_FORMATTING( p )

if (List) {
sprintf(Print_buffer, "%#.*g%s",
DOUBLE_LEN - 7,
*(double *) (var->sqldata), NEWLINE);
UNIX_EXPONENT_FORMATTING( Print_buffer )
ISQL_printf(Out, Print_buffer);
}
}
break;





 All   Comments   Work Log   Change History   Version Control   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Claudio Valderrama C. added a comment - 09/Jun/09 03:50 AM
Are you happy with a much less intrusive solution, that requires only three lines of code, provided that it's applied to FB2.1 and 2.5 but works only with VC2005 and VC2008?

Bill Oliver added a comment - 29/Jun/09 06:37 PM
I confirm this is now fixed in HEAD, thanks!

C:\temp>\sasv9\fbembed\isql \fbdata\FB25.FDB
Database: \fbdata\FB25.FDB
SQL> select cast ('-2.488355210669293e+39' as double precision) from rdb$database;

                   CAST
=======================
 -2.488355210669293e+39

SQL> show version;
ISQL Version: WI-T2.5.0.24271 Firebird 2.5 Beta 1
Server version:
Firebird/x86/Windows NT (access method), version "WI-T2.5.0.24271 Firebird 2.5 Beta 1 "
on disk structure version 11.2
SQL>