#integer cast truncated bits

1 messages · Page 1 of 1 (latest)

devout isle
#

you intCast it to i32 and then bitCast it to i32?

#

i think if you change it to @bitCast(@as(u32, @intCast you'll get what you expected

devout isle
#

const seed: i32 = @bitCast(@as(i32, @intCast(...)));
this is saying "intcast to i32, then bitcast it to i32"

devout isle
open ravine
#

how do you want it to work?

#

what is the input and output range of values you want

#

the negative i32s can't be represented as u32

#

you can easily get i64 -> i32 value conversion as long as they all fit in an i32 with just @intCast

devout isle
#

const seed: i32 = @truncate(std.time.milliTimestamp()); should be all you need then

#

its pretty much the same as what youre doing originally lol

#

if you want the exact same result as your original, you can do this const seed: i32 = @truncate(@mod(in, std.math.maxInt(u32)));