let r: u128 = ...;
u64::try_from(r << 64).unwrap();
but without unwrapping which would be slow. I don't care if the value does not fit u64, I need C++ like static_cast for integer types only, but without unsafe code.
Actually, I need this:
let a: u64 = ...;
let b: u64 = ...;
let r = a.into() as u128 * b.into() as u128;
result = u64::try_from(r & 0xFFFFFFFFFFFFFFFF0000000000000000).unwrap();
result = u64::try_from(r << 64).unwrap();
that is, I need the lower and higher u64 numbers of the u128. Something like to_be_bytes but for u64
You also want 0x0000000000000000FFFFFFFFFFFFFFFF, not 0xFFFFFFFFFFFFFFFF0000000000000000.
Just like in decimal notation, high order bits are on the left side of the number, so you want to shift them right, not further left.
Edit: I think having low-order digits on the left of the number would be more consistent with left-to-right writing systems, but ultimately these are Arabic numerals, and Arabic language is written right-to-left, so maybe that's why we write numbers this way.
Yeah, makes sense, English is big-endian. I would be tempted to argue this might be because of notation, but actually Roman numerals that were used before are also big-endian, even though latin isn't right-to-left.
German uses a hybrid mixed-endian system! 123 in German is "one hundred three twenty". Even worse than big-endian!
I'd say it's very important. Not only does it make it more familiar to English speakers from blackbirds baked in a pie, but it also helps separate it from the French quatre-vingt ("four-twenties") meaning eighty.
I find particularly fascinating that - apparently - in Latin both versions are possible. For example 21 can be "viginti unus" or "unus et viginti".
Also I just noticed that English “-teen”s also kind-of say the number backwards, assuming that the “teen” is just an alternate form of “ten”. (And this assumption is based on the fact that German ”-teen“ numbers are formed the same way, but they use literally the same word as the word for 10 as their suffix.)
I suppose order of words within numbers and order of parts of a sentence are different things. Regarding order of words in a sentence, German is less strict than English but more strict than Latin. For example, adjectives must come before their corresponding nouns in German, while they don’t need to be anywhere close in Latin IIRC. However English requires a particular order of subject, verb, and object in a sentence, and also doesn’t allow anything unrelated in-between those, while German only prescribes the position of the verb in a sentence, while anything else can (usually) go pretty much anywhere (often with the effect of emphasizing different parts of the sentence); order between subject and object is only relevant in cases where declension is ambiguous.