Skip to content

do I get same value if I cast to something then cast back #84064

Answered by huoyaoyuan
Xyncgas asked this question in Q&A
Discussion options

You must be logged in to vote

It's case by case depending on the capacity of the types.

if I cast int64 to uint64, do I get the same integer if I cast this uint64 to int64?

Yes, for integers of same size, the cast is a bitcast.

What about floats

Currently there's no floats with same capacity. If both types have the same base (base-2 or base-10), casting from smaller->bigger->smaller is loseless.
Note that this only applies for "normal' values. I'm not sure the rules about NaN/Infs.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Xyncgas
Comment options

Answer selected by Xyncgas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants