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

Add shorthand cast for DECFLOAT to simplify defining values in literals [CORE6060] #6310

Closed
firebird-automations opened this issue May 3, 2019 · 16 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: @mrotteveel

Block progress on CORE5696
Block progress on CORE5697

Votes: 1

The literal support for DECFLOAT is limited to exact numeric literals of 20 or more digits (eg 1.2345678901234567890), or for approximate numeric literals (scientific notation, normally used for double precision) with a exponent greater than 308 or smaller than -308.

It would be helpful to introduce a shorthand cast, for example DECFLOAT'<signed numeric string>', which would be equivalent to CAST('<signed numeric string>' as DECFLOAT). This would be similar to the shorthand casts that exist for the date/time types.

@firebird-automations
Copy link
Collaborator Author

Modified by: @mrotteveel

description: The literal support for DECFLOAT is limited to exact numeric literals of 20 or more digits (eg 1.2345678901234567890), or for approximate numeric literals (scientific notation, normally used for double precision) with a mantissa greater than 308 or smaller than -308.

It would be helpful to introduce a shorthand cast, for example DECFLOAT'<signed numeric string>', which would be equivalent to CAST('<signed numeric string>' as DECFLOAT). This would be similar to the shorthand casts that exist for the date/time types.

=>

The literal support for DECFLOAT is limited to exact numeric literals of 20 or more digits (eg 1.2345678901234567890), or for approximate numeric literals (scientific notation, normally used for double precision) with a exponent greater than 308 or smaller than -308.

It would be helpful to introduce a shorthand cast, for example DECFLOAT'<signed numeric string>', which would be equivalent to CAST('<signed numeric string>' as DECFLOAT). This would be similar to the shorthand casts that exist for the date/time types.

@firebird-automations
Copy link
Collaborator Author

Commented by: @aafemt

I would rather consider it as a bug "Firebird does not support high precision decimal literals".

@firebird-automations
Copy link
Collaborator Author

Commented by: @mrotteveel

That is an incorrect qualification: Firebird does support them, but you need at least 20 digits otherwise it is a numeric(18,x), which BTW has it is own problems as a literal with 18 or 19 digits is rounded but that is done for backwards compatibility. And the scientific notation is - by the SQL standard - reserved for approximate numeric literals, and Firebird has a non-standard(?) extension that reuses that format for DECFLOAT if the exponent is greater than 308 (absolute).

My request is for a bit of support to make it simpler to produce DECFLOAT values with less digits or with a smaller exponent.

@firebird-automations
Copy link
Collaborator Author

Commented by: @dyemanov

This way one could also suggest smallint '1', bigint '1', etc.

@firebird-automations
Copy link
Collaborator Author

Commented by: @mrotteveel

Those values are easy to enter as normal literals.

@firebird-automations
Copy link
Collaborator Author

Commented by: @dyemanov

In your case, the literal is parsed as NUMERIC but you want DECFLOAT. In my case, it's parsed as INT but I want BIGINT. I don't see a big difference here.

@firebird-automations
Copy link
Collaborator Author

Commented by: @mrotteveel

But those literal values are convertible to bigint or smallint without loss of precision, the same can't be said for reasonable decfloat values. Say I want 2.33333e-32 as a decfloat value, I must use cast('2.33333e-32' as decfloat), otherwise I'll get a double precision with loss of precision. If that is then converted to DECFLOAT (eg assignment conversion), then the resulting value is 2.3333299999999999E-32

Being able to use DECFLOAT'2.33333e-32' or DECFLOAT '2.33333e-32' will be simpler and cause less visual clutter than a cast.

@firebird-automations
Copy link
Collaborator Author

Modified by: @AlexPeshkoff

Link: This issue block progress on CORE5696 [ CORE5696 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @AlexPeshkoff

@ds - I fully agree with you, and I plan to fix DECFLOAT literals instead implementing this issue

@firebird-automations
Copy link
Collaborator Author

Modified by: @AlexPeshkoff

Link: This issue block progress on CORE5697 [ CORE5697 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @sim1984

And my opinion is still on the side of Mark. There is nothing wrong with the server recognizing a literal as INT instead of BIGINT. However, if DOUBLE PRECISION is used instead of DECFLOAT, this means a loss of precision. You need a simple way to go to the calculations with high precision.

@firebird-automations
Copy link
Collaborator Author

Commented by: @mrotteveel

Alex, fixing DECFLOAT literals how? I can't see a way to do that without breaking backwards compatibility for current behaviour of approximate numeric precision literals or exact numeric precision literals.

@firebird-automations
Copy link
Collaborator Author

Commented by: @AlexPeshkoff

Use of any datatype instead DECFLOAT may be wrong - for example, 2 & 2.00 are distinct things from decfloat POV. When using int to represent them you loose precision info.

How to fix - I will be able to exactly answer this after the fix.

@firebird-automations
Copy link
Collaborator Author

Commented by: @mrotteveel

From the SQL standard perspective, the only option is to redefine the approximate numeric precision literals to decfloat instead of double precision. Redefining the exact numeric precision literals to DECFLOAT would not be 'correct'.

See SQL:2016-2 section 4.4:

"""
An <approximate numeric literal> ANL consists of a <mantissa> that is an <exact numeric literal>, the letter 'E' or 'e', and an <exponent> that is a <signed integer>. It is implementation-defined whether the declared type of ANL is an approximate numeric type or the decimal floating-point type.
"""

and section 5.3, syntax rules:

"""
22) The declared type of an <exact numeric literal> ENL is an implementation-defined exact numeric type whose scale is the number of <digit>s to the right of the <period>. There shall be an exact numeric type capable of representing the value of ENL exactly.

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.
"""

@firebird-automations
Copy link
Collaborator Author

Modified by: @AlexPeshkoff

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

resolution: Won't Fix [ 2 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

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

1 participant