Tag: integer
-
Emulating signed integers using unsigned integers in C
11 In Jens Gustedt’s book Modern C, on page 59, he explains how signed integers can be emulated using unsigned integers. His example code shows how one can implement a comparison of two unsigned integers reinterpreted as signed integers: bool is_negative(unsigned a) { unsigned const int_max = UINT_MAX /2; return a > int_max; } bool…
-
How can I multiply a INumber with an int?
15 How should I implement the multiplication by int (z * 2) on the last line? public static TResult Test<TResult>() where TResult : INumber<TResult> { TResult x = TResult.AdditiveIdentity; TResult y = TResult.MultiplicativeIdentity; TResult z = x * y; TResult z2 = z * 2; // <— this gives the CS0019 error "The operator *…