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

DECFLOAT should not throw exceptions when +/-NaN, +/-sNaN and +/-Infinity is used in comparisons [CORE5699] #5965

Closed
firebird-automations opened this issue Jan 7, 2018 · 10 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: @mrotteveel

Replaces CORE5698

The datatype DECFLOAT currently supports storing +/-NaN, +/-sNaN and +/-Infinity (because the underlying Decimal64 / Decimal128 supports that), this should be disallowed and when attempting to store these values, a "data exception — numeric value out of range" error (or equivalent) should be raised. Storing these values can be achieved by either storing it using parameters, or using conversion from string.

See also SQL:2016, 6.29 <numeric value expression>.

Currently Firebird already disallows overflow to +/- Infinity during calculations with DECFLOAT, nor is it (or should it be possible) to produce NaN during calculation.

Currently, storing +/-NaN or +/-sNaN in a column can lead to problems, for example in a select with a condition involving a decfloat column, having a NaN in that column leads to an error during fetch:

====
*** IBPP::SQLException ***
Context: Statement::Fetch
Message: isc_dsql_fetch failed.

SQL Message : -901
Unsuccessful execution caused by system error that does not preclude successful execution of subsequent statements

Engine Code : 335545141
Engine Message :
Decimal float invalid operation. An indeterminant error occurred during an operation.

Commits: d0d92de

====== Test Details ======

See functional\datatypes\decfloat-nan-and-infinity-comparison.fbt

@firebird-automations
Copy link
Collaborator Author

Modified by: @AlexPeshkoff

Link: This issue replaces CORE5698 [ CORE5698 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @AlexPeshkoff

assignee: Alexander Peshkov [ alexpeshkoff ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @AlexPeshkoff

Making it impossible to store special decimal float values in a field does not look like good idea. We can store such values in double field:
SQL> show table dou;
V DOUBLE PRECISION Nullable
SQL> select * from dou;

                  V 

=======================
0.5000000000000000
Infinity
NaN

(I've used c++ program to add such records to the table - insert with parameter.)
What should better be fixed is use of such values in comparison operators - with double precision values that works somehow:

SQL> select v, v < 1 from dou;

                  V         

======================= =======
0.5000000000000000 <true>
Infinity <false>
NaN <true>

@firebird-automations
Copy link
Collaborator Author

Commented by: @mrotteveel

That could also work.

As far as I can tell from the SQL standard, technically double precision shouldn't support NaN and infinities either, but as we already do that, we could extend that to DECFLOAT as well.

@firebird-automations
Copy link
Collaborator Author

Modified by: @AlexPeshkoff

summary: DECFLOAT should disallow +/-NaN, +/-sNaN and +/-Infinity => DECFLOAT should not through exceptions when +/-NaN, +/-sNaN and +/-Infinity is used in comparisons

@firebird-automations
Copy link
Collaborator Author

Modified by: @AlexPeshkoff

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

resolution: Fixed [ 1 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @mrotteveel

summary: DECFLOAT should not through exceptions when +/-NaN, +/-sNaN and +/-Infinity is used in comparisons => DECFLOAT should not throw exceptions when +/-NaN, +/-sNaN and +/-Infinity is used in comparisons

@firebird-automations
Copy link
Collaborator Author

Modified by: @AlexPeshkoff

Fix Version: 4.0 Beta 1 [ 10750 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pavel-zotov

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

QA Status: No test => Covered by another test(s)

Test Details: See functional\datatypes\decfloat-nan-and-infinity-comparison.fbt

@firebird-automations
Copy link
Collaborator Author

Modified by: @pavel-zotov

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

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

No branches or pull requests

2 participants