Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isql exponential format of numbers has zero pad on windows [CORE1171] #1594

Closed
firebird-issue-importer opened this issue Mar 16, 2007 · 16 comments
Closed

Comments

@firebird-issue-importer

Submitted by: Bill Oliver (verbguy)

Assigned to: Claudio Valderrama C. (robocop)

Is related to QA260

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, "% #&#x2060;\*\.\*g ", \(int\) length,
					\(int\) MIN\(16, \(int\) \(length \- 7\)\),
					\*\(double \*\) \(var\-\>sqldata\)\);
			UNIX\_EXPONENT\_FORMATTING\( p \)

			if \(List\) \{
				sprintf\(Print\_buffer, "%#&#x2060;\.\*g%s",
						DOUBLE\_LEN \- 7,
						\*\(double \*\) \(var\-\>sqldata\), NEWLINE\);
				UNIX\_EXPONENT\_FORMATTING\( Print\_buffer \)
				ISQL\_printf\(Out, Print\_buffer\);
			\}
		\}
		break;

Commits: 024d840 d69d80f

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Jan 28, 2008

Modified by: @pcisar

Workflow: jira [ 11699 ] => Firebird [ 15526 ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Jun 9, 2009

Commented by: Claudio Valderrama C. (robocop)

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?

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Jun 9, 2009

Modified by: Claudio Valderrama C. (robocop)

assignee: Claudio Valderrama C. [ robocop ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Jun 17, 2009

Modified by: Claudio Valderrama C. (robocop)

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

Fix Version: 2.1.3 [ 10302 ]

Fix Version: 2.5 RC1 [ 10300 ]

Fix Version: 2.5.0 [ 10221 ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Jun 29, 2009

Commented by: Bill Oliver (verbguy)

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>

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Oct 19, 2009

Modified by: @dyemanov

Fix Version: 2.5.0 [ 10221 ] =>

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Feb 23, 2011

Modified by: @pcisar

Link: This issue is related to QA260 [ QA260 ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented May 9, 2011

Modified by: byvoig12

Attachment: 1.html [ 11947 ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented May 9, 2011

Modified by: byvoig12

Attachment: 2 [ 11948 ]

Attachment: 3.txt [ 11949 ]

Attachment: 4.pdf [ 11950 ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented May 9, 2011

Modified by: @pcisar

Attachment: 1.html [ 11947 ] =>

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented May 9, 2011

Modified by: @pcisar

Attachment: 2 [ 11948 ] =>

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented May 9, 2011

Modified by: @pcisar

Attachment: 3.txt [ 11949 ] =>

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented May 9, 2011

Modified by: @pcisar

Attachment: 4.pdf [ 11950 ] =>

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented May 24, 2011

Modified by: @pmakowski

status: Resolved [ 5 ] => Closed [ 6 ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Jan 19, 2016

Modified by: @pavel-zotov

QA Status: No test

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Jan 19, 2016

Modified by: @pavel-zotov

QA Status: No test => Done successfully

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment