generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 140
Java: Numeric Type Promotion #2224
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
Open
MattSchur
wants to merge
10
commits into
main
Choose a base branch
from
java-type-promotion
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f1a01a9
Java: Numeric Type Promotion
MattSchur 2faeb44
Merge branch 'main' into java-type-promotion
agoerler 2c001ff
Update java/cds-data.md
agoerler 31cff7a
Add Numeric Standard Functions
MattSchur 7596e67
Apply suggestions from code review
MattSchur 9c85d54
Update java/cds-data.md
MattSchur fa7436a
Apply suggestions from code review
MattSchur dba75da
Apply suggestions from code review
MattSchur 35dfefb
Merge branch 'main' into java-type-promotion
renejeglinsky f2ee305
Apply suggestion from @smahati
smahati File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,6 +71,22 @@ The framework isn't responsible for closing the stream when writing to the datab | |
|
|
||
| These types are used for the values of CDS elements with primitive type. In the [Model Reflection API](./reflection-api), they're represented by the enum [CdsBaseType](https://javadoc.io/doc/com.sap.cds/cds4j-api/latest/com/sap/cds/reflect/CdsBaseType.html). | ||
|
|
||
| ### Numeric Type Promotion in Expressions { #numeric-promotion } | ||
|
|
||
| To have a consistent behavior across different databases, numeric type promotion in arithmetic expressions is handled by the CAP Java runtime. Arithmetic expressions promote numeric types according to the following precedence: | ||
|
|
||
| **Type Precedence (highest to lowest):** | ||
| `DOUBLE` (binary64), `HANA_REAL` (binary32), `DECIMAL` (base 10), `INT64`, `INT32`, `INT16`, `UINT8` | ||
MattSchur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - For addition, subtraction, and multiplication, the result type is the one with highest precedence among the operands. | ||
| - For division: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a colon after "For division" to maintain consistency with the formatting of "For addition, subtraction, and multiplication" above: - For division: |
||
| - If any operand is a binary floating-point type (`DOUBLE`, `HANA_REAL`), the result type is `DOUBLE` (binary64). | ||
| - Otherwise, the result type is `DECIMAL` (base 10), which provides higher accuracy for decimal fractions. | ||
agoerler marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ::: tip | ||
| Use `type(CdsBaseType)` to explicitly set the result type if needed. | ||
| ::: | ||
|
|
||
| ## Structured Data | ||
|
|
||
| In CDS, structured data is used as payload of *Insert*, *Update*, and *Upsert* statements. Also the query result of *Select* may be structured. | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.