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 underflow should yield zero instead of an error [CORE5700] #5966

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

Comments

@firebird-issue-importer
Copy link

@firebird-issue-importer firebird-issue-importer commented Jan 7, 2018

Submitted by: @mrotteveel

A DECFLOAT underflow (that is if the exponent is smaller than the minimum supported exponent), currently yields an error. However, based on the rules in SQL:2016 5.3 <literal> and 6.13 <cast specification>, this should instead yield 0 (either really 0E0, or maybe 0E<lowest valid exponent>).

Specifically from 5.3 (full quote below): ""Underflow", i.e., specifying a nonzero value so close to 0 (zero) that the closest representation in the SQL-implementation's internal representation is 0E0, is a special case of the latter condition, and is not a syntax error"

====
*** 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 : 335545143
Engine Message :
Decimal float underflow. The exponent of a result is less than the magnitude allowed.

"""
23) It is implementation-defined whether the declared type of an <approximate numeric literal> ANL is an implementation-defined approximate numeric type or the decimal floating-point type with an implementation-defined precision. If the declared type of ANL is an approximate numeric type, then the value of ANL shall not be greater than the maximum value nor less than the minimum value that can be represented by the approximate numeric types. If the declared type of ANL is the decimal floating-point type, then the value of ANL shall not be greater than the maximum value nor less than the minimum value that can be represented by the decimal floating-point type.

NOTE 142 — Thus the only syntax error for an <approximate numeric literal> is what is commonly known as "overflow"; there is no syntax error for specifying more significant digits than the SQL-implementation can represent internally, nor for specifying a value that has no exact equivalent in the SQL-implementation's internal representation. ("Underflow", i.e., specifying a nonzero value so close to 0 (zero) that the closest representation in the SQL-implementation's internal representation is 0E0, is a special case of the latter condition, and is not a syntax error.)
"""

Commits: b3f157f a372f31 FirebirdSQL/fbt-repository@6da9c8a

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

See also test for CORE4409

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Jan 7, 2018

Commented by: @mrotteveel

This would be needed both when specifying literal, casting from decfloat(34) to decfloat(16), casting from double precision to decfloat, casting from string to a decfloat, and if the result in a calculation causes an underflow.

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Jan 24, 2018

Commented by: @mrotteveel

The definition in 4.4.2 Characteristics of numbers is probably clearer support for the fact this also applies to the result of calculations:

"""
An approximation obtained by truncation or rounding of a numeric value N for an approximate numeric type T or the decimal floating-point type T is a value V in T such that there is no numeric value in T distinct from that of V that lies between the numeric value of V and N, inclusive.

If there is more than one such value V then it is implementation-defined which one is taken. It is implementation-defined which numeric values have approximations obtained by rounding or truncation for a given approximate numeric type or a given decimal floating-point type.

Whenever a numeric value is assigned to an approximate numeric value site or a decimal floating-point value site, an approximation of its value is represented in the declared type of the target. The value is converted to have the precision of the target.
"""

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Feb 2, 2018

Modified by: @AlexPeshkoff

assignee: Alexander Peshkov [ alexpeshkoff ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Feb 2, 2018

Commented by: @AlexPeshkoff

One can tune desired set of DECFLOAT traps using
SET DECFLOAT TRAPS TO trap1, trap2, etc.;
but certainly I agree - default should match standard. What we had before was default recommended by decNumber library.

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Feb 2, 2018

Modified by: @AlexPeshkoff

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

resolution: Fixed [ 1 ]

Fix Version: 4.0 Beta 1 [ 10750 ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Feb 5, 2018

Modified by: @pavel-zotov

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

QA Status: No test => Deferred

Test Details: Sent letter to Alex, 50-feb-18 19^12. Waiting for reply.

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Feb 5, 2018

Modified by: @pavel-zotov

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

Test Details: Sent letter to Alex, 50-feb-18 19^12. Waiting for reply. => Sent letter to Alex, 05-feb-18 19:12. Waiting for reply.

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Feb 5, 2018

Modified by: @pavel-zotov

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

QA Status: Deferred => Done successfully

Test Details: Sent letter to Alex, 05-feb-18 19:12. Waiting for reply. =>

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Feb 5, 2018

Modified by: @pavel-zotov

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

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Aug 12, 2018

Modified by: @pavel-zotov

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

Test Details: See also test for CORE4409

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

Successfully merging a pull request may close this issue.

None yet
2 participants