Issue Details (XML | Word | Printable)

Key: CORE-2315
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Bill Oliver
Reporter: Bill Oliver
Votes: 0
Watchers: 1
Operations

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

Firebird float support does not conform to Interbase spec

Created: 10/Feb/09 03:41 PM   Updated: 31/May/11 12:02 PM
Component/s: Engine
Affects Version/s: 2.0.0, 1.5.4, 2.0.1, 2.0.2, 2.0.3, 1.5.5, 2.1.0, 2.0.4, 2.5 Alpha 1, 2.1.1, 2.0.5
Fix Version/s: 2.5 RC1

Time Tracking:
Not Specified

Environment: tested on windowsxp and AIX, problem is portable
Issue Links:
Relate
 

Planning Status: Unspecified


 Description  « Hide
The Interbase documentation says that a float value should have a range from 1.175E-38 to 3.402E38. But, the largest value I can put in appears to be just under 3.4E38. 3.4E38 or higher results in overflow.

This came up when running the JDBC-CTS tests against Firebird embedded. Thanks go to my co-worker Dave M.

This was fixed in SAS Vulcan (S0275993). The code in jrd/cvt.cpp is using hard-coded 3.4E38 instead of the proper FLT_MAX symbol which is 3.402823466e+38F. Fix provided to Alex for review.

Here is bad test case:

create table float_test (i integer, f float);
insert into float_test values (1, 3.0);
insert into float_test values (1, 3.402823466e+38);

produces this output:
insert into float_test values (1, 3.402823466e+38);
Statement failed, SQLSTATE = 22003
arithmetic exception, numeric overflow, or string truncation
-numeric value is out of range

Here is correct results with my patch:

SQL> create table float_test (i integer, f float);
SQL> insert into float_test values (1, 3.0);
SQL> insert into float_test values (1, 3.402823466e+38);
SQL> select * from float_test;

           I F
============ ==============
           1 3.0000000
           1 3.4028235e+38





 All   Comments   Work Log   Change History   Version Control   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Alexander Peshkov added a comment - 24/Feb/09 11:59 AM
Fincal patch is decided to be:

#ifdef FLT_MAX
#define FLOAT_MAX FLT_MAX /* Approx. 3.4e38 max float (32 bit) value */
#else
#define FLOAT_MAX 3.4e38 /* max float (32 bit) value */
#endif

Added not to forget after beta1.

Claudio Valderrama C. added a comment - 09/Mar/09 04:38 AM
Beware that the documentation says:

Of these macros, only FLT_RADIX is guaranteed to be a constant expression. The other macros listed here cannot be reliably used in places that require constant expressions, such as `#if' preprocessing directives or in the dimensions of static arrays.

Alexander Peshkov added a comment - 10/Mar/09 06:24 AM
May be I'm dumb, but where do you see use of FLT_MAX with #if or as static array index?

Bill Oliver added a comment - 15/Sep/09 04:04 AM
fixed for 2.5 RC 1

Pavel Cisar added a comment - 31/May/11 12:02 PM
QA test added.