`if` Statement doesn't work??? :astonished:
Consider this:
Then run
mojo
, I got this:
Hmmm, 2
is definitely lesser than Self.MAX
=590295810358705651711
, what happened? @ModularStaff5 Replies
Int
is backed by the MLIR index
type, which is pointer-sized. The current Mojo release is 64-bit, so Int
can only store up to 64 bits. Hence, alias MAX: Int = 590295810358705651711
gets truncated to be equivalent to alias MAX: Int = -1
. Then, 2 is not lesser than -1, which causes the code path you are experiencing to be followed.Will there eventually be support for i128 and u128 integer types?
Thank you for your reply, that is an excellent explanation! I wonder how can one make use of IntLiteral to cast it into u69 at compile time then uses it at runtime with @nonmaterializable decorator.
I don't think we have a user-accessible way to do this right now (there is an undocumented MLIR op that does it, but I'm hearing that it can be buggy in some cases at the moment). I talked to another member of the Modular staff who is working in this area and they mentioned that they are likely to add a cast method to IntLiteral in the future that should be officially supported, so keep an eye on the changelog.
Good day to you sir, thank you for checking in with your colleagues on this - I think it's pretty groundbreaking with how Mojo allows for direct interfacing with MLIR and allows developers to go wild with more compile time programming 🚀