dotnet / dotnet/vblang

New CVal conversion operator for native integer conversions

Open
#85 11 comments 2 reactions 1 assignee Claimed by @AnthonyDGreen View on GitHub
Proposal Speclet-Needed
Dominant language
No language data
Stars
328
Forks
71
PR merge metrics
No merged PRs in 30d

Description

This idea addresses scenarios #82 and #83.

This new operator would take the form: **`CVal(`_\_`,` _\_`)`**

Where _\_ can be of the following types:

* Object type: `Object`
* Signed integers: `SByte, Int16, Int32, Int64`
* Unsigned integers: `Byte, UInt16, UInt32, UInt64`
* Floating-Point: `Single, Double, Decimal`
* Character type: `Char`
* Any enumeration type

Note: This **excludes** type parameter types.

And _\_ can be any of the above types excluding `Object`.

Note: This **excludes** type parameter types.

The behavior is as follows:
* From Object to any valid target type, a native CLR unbox conversion shall be used.
* Between signed and unsigned integers, the bits of the integer shall be re-interpreted with the new type.
* If the destination type has more bits than the source type the result shall be [sign-extended](https://en.wikipedia.org/wiki/Sign_extension).
* If the destination type has fewer bits than the source type, the result shall truncate the excess bits.
* From any floating-point type to a signed integer type, the fractional portion of the floating-point value shall be truncated.
* For negative values this truncates "up" to zero.
* From the character type to any signed or unsigned integer type, the result shall be the Unicode 16 value of the character.
* From any signed or unsigned integer type to the character type, the result shall be the character indicated by that Unicode 16 value.
* For values larger than 16-bits, excess bits shall be truncated.
* Conversions to or from enumeration types shall behave as if those conversions were being performed to or from the underlying integer type of the enumeration.
* Conversion overflow/underflow checking is governed by the checked/unchecked settings of the project.

Open questions:
- [ ] Nullable/lifted conversions
- [ ] Conversions between Boolean and integer types
- [ ] Reconcile behavior being orthogonal to overflow/underflow settings with above behavior that truncates excess bits.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.