mojo icon indicating copy to clipboard operation
mojo copied to clipboard

[BUG]: Wrong values being printed for UI32 and UI64 types

Open abhinav-upadhyay opened this issue 1 year ago • 4 comments

Bug description

When printing the values of UI32 or UI64 types, the print function sometimes print wrong values. It seems to work fine for UI8 and UI16 types in similar cases.

Steps to reproduce

let j: UI64 = 2 ** 64 - 1
print(j)
# Output 18

let j: UI32 = 2 ** 32 - 1
print(j)
# Output -1

If you do this, then you get the right answer.

let j: UI32 = 2 ** 32 - 1
print(j.to_int())
# Output: 4294967295 

System information

11:hugetlb:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod7b7a3609_944c_4f80_b48f_a45df30fae30.slice/cri-containerd-941f72a8548befda1545263fed1cbd8fdd0fd8b48e7251dce3dca63016363a33.scope
10:memory:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod7b7a3609_944c_4f80_b48f_a45df30fae30.slice/cri-containerd-941f72a8548befda1545263fed1cbd8fdd0fd8b48e7251dce3dca63016363a33.scope
9:blkio:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod7b7a3609_944c_4f80_b48f_a45df30fae30.slice/cri-containerd-941f72a8548befda1545263fed1cbd8fdd0fd8b48e7251dce3dca63016363a33.scope
8:devices:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod7b7a3609_944c_4f80_b48f_a45df30fae30.slice/cri-containerd-941f72a8548befda1545263fed1cbd8fdd0fd8b48e7251dce3dca63016363a33.scope
7:pids:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod7b7a3609_944c_4f80_b48f_a45df30fae30.slice/cri-containerd-941f72a8548befda1545263fed1cbd8fdd0fd8b48e7251dce3dca63016363a33.scope
6:freezer:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod7b7a3609_944c_4f80_b48f_a45df30fae30.slice/cri-containerd-941f72a8548befda1545263fed1cbd8fdd0fd8b48e7251dce3dca63016363a33.scope
5:net_cls,net_prio:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod7b7a3609_944c_4f80_b48f_a45df30fae30.slice/cri-containerd-941f72a8548befda1545263fed1cbd8fdd0fd8b48e7251dce3dca63016363a33.scope
4:cpuset:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod7b7a3609_944c_4f80_b48f_a45df30fae30.slice/cri-containerd-941f72a8548befda1545263fed1cbd8fdd0fd8b48e7251dce3dca63016363a33.scope
3:perf_event:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod7b7a3609_944c_4f80_b48f_a45df30fae30.slice/cri-containerd-941f72a8548befda1545263fed1cbd8fdd0fd8b48e7251dce3dca63016363a33.scope
2:cpu,cpuacct:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod7b7a3609_944c_4f80_b48f_a45df30fae30.slice/cri-containerd-941f72a8548befda1545263fed1cbd8fdd0fd8b48e7251dce3dca63016363a33.scope
1:name=systemd:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod7b7a3609_944c_4f80_b48f_a45df30fae30.slice/cri-containerd-941f72a8548befda1545263fed1cbd8fdd0fd8b48e7251dce3dca63016363a33.scope
0::/

abhinav-upadhyay avatar Jun 04 '23 09:06 abhinav-upadhyay

The issue here is that literals are currently hard coded to integer type, we don't have an model for arbitrary precision literals yet (but we have ideas on that). 2**64 will overflow, but I'm surprised that you're getting 18. @Mogball can you take a look at what is happening here next week?

lattner avatar Jun 04 '23 17:06 lattner

This seems more like a problem in the print method for SIMD types. I'll TAL

Mogball avatar Jun 05 '23 16:06 Mogball

The issue here is that literals are currently hard coded to integer type, we don't have an model for arbitrary precision literals yet (but we have ideas on that). 2**64 will overflow

Oops, I should have thought about the overflow. But I guess it should have worked for the UI32 example.

BTW, UI32 and UI64 et al are all SIMD data types. Are there scalar equivalents for these as well? Or are these the scalar equivalents?

abhinav-upadhyay avatar Jun 05 '23 17:06 abhinav-upadhyay

UI32 (now called UInt32) are the scalar things

Mogball avatar Jun 05 '23 17:06 Mogball