numeric types #2
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Is that a good idea? Concretely I'm thinking of things like a function breaking if a constant is set too high (since now we can't add int32 and int64). I can imagine that breakage being quite non-obvious to new users.
For writing functions, one can use a type variable over numerical types to allow users to use int32/int64/float. One problem is casting constants within the function to the type that the type variable denotes, but I think we can add special rules if needed to solve this problem (for example, let
x
be the type variable, maybe we can allow something likex(123)
to cast 123 intoint32/int64/float
).For the users, I cannot think of a good way to avoid confusion in this case. Maybe we can prohibit the user to use anything not in the range of
int32
, except when they wrap it in something likeint64(......)
? This makes it explicit.What does rust do for default numeric types?
I think it would require suffix for
i64
.I would recommend that overflows from int32 or uint32 be treated as such, and not turned subtly into in64 or uint64. For one thing, some algorithms make use of overflows as a feature. Also, then you don't have issues with a variable having been changed subtly to some other type (say int64), and then being used later as an argument to a method that requires an int32 input, for example.
I think the onus should be on the programmer here -- if they are working with numbers that need to go larger than what can be held in 32 bits, then they should write their function to use 64-bit numbers explicitly. I don't think the compiler should try to guess their intentions and "correct" by changing 32-bit ints to 64-bit ones.
I agree with @dhslichter .
This is now mentioned in the current README.