Open soraros opened 1 week ago
This will conflict with Python's format spec. We could constraint your proposal to SIMD only, but that would mean also deviating for floats which don't have a separate "independent" type like Int. Another option is to make overloads/use a parameter (default false) to deviate from the format spec.
Come think about it, we could just put them in the bit
module.
Review Mojo's priorities
What is your request?
As title.
What is your motivation for this change?
In Python, the
bin
andhex
functions return variable-length binary/hexadecimal string representations forint
values. Python also follows a convention where negative numbers are represented as-0bXXXX
, withXXXX
being the binary/hexadecimal representation of the corresponding positive number. This convention primarily makes sense when working with arbitrarily large integers.Mojo, on the other hand, uses machine integer types, which have well-defined binary/hexadecimal representations (e.g., two's complement for negative numbers). Introducing fixed-width variants of
bin
andhex
functions would not only enhance their utility in low-level programming but also offer a potential performance improvement since the buffer size can be predetermined.Any other details?
N/A