I understand that there are operations to be used explicitely for this, namely SIToFP, FPToSI, etc., but isn’t there already some sort of a wrapper that can automatically cast a value of builtin type given the desired builtin destination type? I understand that I can do it by myself, but that would be a huge amount of if-else cases.
Side question: I can’t completely get what Signless integer means. From my understanding, it’s not the same of an unsigned integer, as it would make no sense to exist. Is it a superset of both signed and unsigned integers, meaning that we don’t care about the value having a sign or not? I read this topic but I did not manage to fully understand the point.
No, there is no such operation. The semantics of this operation would be quite complicated to reason about, up to a point where it will be essentially a list of operations embedded into one. For example, if you want to convert an i32
into and f64
, do you first extend (and do you zero-extend or sign-extend) the integer and then convert to float, or do you first convert to float and then extend? The result is different depending on the order, and parameters of individual operations.
Signless integer means that the type does not assign any meaning to the highest bit. Specific operations do instead. For example, assuming two’s complement representation, it is not important for add
or sub
whether the highest bit is a sign bit or a value bit. It is, however, important for, e.g., division. In the latter case, we have two ops that treat the highest bit differently.
Ok, so it’s basically up to me to decide how to interpret integers in first place and then dispatch them to the right division operation. Very thanks for your help!