Why is type conversion from u64 to usize allowed using `as` but not `From`?

as casts are fundamentally different from From conversions. From conversions are “simple and safe” whereas as casts are purely “safe”. When considering numeric types, From conversions exist only when the output is guaranteed to be the same, i.e. there is no loss of information (no truncation or flooring or loss of precision). as casts, however, … Read more

Infinity vs Number.POSITIVE_INFINITY

TL;DR Infinity used to be overwritable; Number.POSITIVE_INFINITY and Number.NEGATIVE_INFINITY have always been read only. Infinity is a property of the global object (window is the global object for Javascript run in the browser), whereas Number.POSITIVE_INFINITY is a property of the Number constructor. Prior to the 5th Edition of ECMAScript, value properties of the global object … Read more

Obscure / encrypt an order number as another number: symmetrical, “random” appearance?

Pick a 8 or 9 digit number at random, say 839712541. Then, take your order number’s binary representation (for this example, I’m not using 2’s complement), pad it out to the same number of bits (30), reverse it, and xor the flipped order number and the magic number. For example: 1 = 000000000000000000000000000001 Flip = … Read more

Why aren’t rational numbers implemented and stored as fractions with zero loss of information? [closed]

The reason they are not stored this way by default is that the range of valid values that can fit in a fixed set of bits is smaller. Your float class can store numbers between 1/MAXINT and MAXINT (plus or minus). A C/C++ float can represent numbers between 1E+37 and 1E-37 (plus or minus). In … Read more

Why does bitwise “not 1” equal -2?

There are 2 integers between 1 and -2: 0 and -1 1   in binary is 00000000000000000000000000000001 0   in binary is 00000000000000000000000000000000 -1 in binary is 11111111111111111111111111111111 -2 in binary is 11111111111111111111111111111110 (“binary” being 2’s complement, in the case of a bitwise not ~ ) As you can see, it’s not very surprising ~1 equals -2, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)