How to convert for example Int8 to Int

mojo 24.6.0

I’m trying to accomplish something very simple:

var i8: Int8 = -1
i = Int(i8)

this results in an error:
error: no matching function in initialization

So how to convert sized numerical types to Int or UInt? The other way around works well. I figured out how to convert sized numerical types to eachother using SIMD cast. But how to convert to Int or UInt is a mystery for now.

In the meantime i found out that i can use:

var i8: Int8 = -1
i = int(i8)

So int() instead of Int() does the trick. But what if i wanted UInt?

When you update to 25.1.0, the Int(i8) will work! See Mojo🔥 changelog | Modular

Which I think should generally answer your question about conversions, but there is also cast.

3 Likes

After updating to Mojo 25.1 i can confirm that Int() works as expected. Uint() doesn´t… The sized UInt*() constructors do seem to work.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.