History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: CORE-1171
Type: Improvement Improvement
Status: Open Open
Priority: Minor Minor
Assignee: Unassigned
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: 16/Mar/07 03:17 PM
Component/s: ISQL
Affects Version/s: 1.5.4, 2.0.0, 2.0 RC5, 2.0 RC4, 2.0 RC3, 2.0 RC2, 2.0 RC1, 2.0 Beta 2, 2.0 Beta 1, 1.5.3, 1.5.2, 1.5.1, 1.5.0, 1.5 RC9, 1.5 RC8, 1.5 RC7, 1.5 RC6, 1.5 RC5, 1.5 RC4, 1.5 RC3, 1.5 RC2, 1.5 RC1, 1.5 Beta 4, 1.5 Beta 3, 1.5 Beta 2, 1.5 Beta 1, 1.5 Alpha 5, 1.5 Alpha 4, 1.5 Alpha 3, 1.0.3, 1.0.2, 1.0.1, 1.0.0, 1.0 RC2, 1.0 RC1, 0.9.5, 0.9.4, 0.9
Fix Version/s: None

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown
Environment: windows


 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:
There are no comments yet on this issue.