:mega: The proposal for unsigned integer types: <h...
# language-proposals
i
📣 The proposal for unsigned integer types: https://github.com/Kotlin/KEEP/issues/135
😆 2
🤘 2
🎉 9
👍 10
1
k
Awesome, I've been looking forward to this! A question: how are the unsigned arrays implemented? How do they map to unsigned types? Also with inline classes?
i
Given that the compactness of storage is a requirement, unsigned arrays can also be inline classes wrapping the signed ones. Though there are other options in other platforms.
👍 1
a
About the bitwise, why not implementing both
shr
and
ushr
?
k
That's mentioned as one of the options.
a
Yeh I noticed, I think both will be the best option as it will create a confusion between their signed counterparts
k
Both creates confusion too, what if both are used together in a project while there's no difference between them?
a
An inspection will be thrown, think it will cover that
k
Might as well just pick one then.
a
Ok
Also, about the number literals, why not detecting if the number is out of the signed range, if so auto change it to it's unsigned form
k
Number literals, right? fixed
a
Got me there @karelpeeters these are number literals 😁
k
You're giving up some explicitness in order to have to type a single letter
u
less, I don't think that's worth it.
e
it's really a pity they wont extend
Number
isn't possible to convert Number in an interface?
a
Maybe make an abstract class
UnsignedNumber
k
I don't really "get" the Number interface, there's not much you can do with them, right?
1
e
what's the point to have it as an abstract class then?
with an unique common base one could use Number for a generic number, unsigned included
k
The interface is not the problem, it's the general idea: what can I do with a
Number
? There are some methods like
.toDouble()
, but those aren't useful because the result is not guaranteed to fit/be as accurate.
r
you can use it in generics bound
👍 1
k
Then what? I now have a value that implements
Number
, but I can't do anything with it.
e
Exactly, I have for example in imgui a methods accepting a generic
Number
which can be either
Int
,
Float
,
Double
or
Long
. The original c++ version actually uses also unsigned. I won't be able to use the stlib unsigned because of this issue
anyway, the point here is: can inline classes extend interfaces?
a
I think so..... How do I enable this feature tho?
k
If you only allow some number types I think overloading is better. (until we have union types)
@elect From https://github.com/Kotlin/KEEP/blob/unsigned_types/proposals/inline-classes.md:
Inline class can implement only interfaces
e
that's a very good news, thanks