Skip to content

[FEATURE] Add support for explicit casting  #10

@TheGupta2012

Description

@TheGupta2012

Feature Description

Users can use explicit casting format to cast values from 1 type to another. Eg. -

const float[64] f1 = 2.5;
uint[8] runtime_u = 7;

// Valid statements

const int[8] i1 = int[8](f1);  // `i1` has compile-time value 2.
const uint u1 = 2 * uint(f1);  // `u1` has compile-time value 4.

// Invalid statements

const bit[2] b1 = bit[2](f1);  // `float[64]` cannot be cast to `bit[2]`.
const int[16] i2 = int[16](runtime_u);  // Casting runtime values is not `const`.

The cast operator translates to the Cast object in openqasm parser but is not parsed by our semantic analyser. We should be able to handle explicit casting statements and have the ability to identify which statements are valid / invalid.

Implementation (Optional)

Most likely changes will be needed in the declaration and assignment handlers for the semantic analyser. Although we have support for implicit casting, we would need to expand to also consider the exact sizes mentioned in the explicit type cast.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestqasm3Related to openqasm3qasm3-coverageAdding support for qasm3 constructsunitary-hackIssues for the Unitary Hack

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions