
|
If you were logged in you would be able to see more operations.
|
|
|
|
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;
|
|
Description
|
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;
|
Show » |
|