min is treating its inputs as chars. That's why it shows the character '#' next to 35, because the ascii value of 35 is #. The numbers you are giving are out of the range of a char, so they are wrapping. You're really doing min(291%256, 682%256) which is min(35,...

fastestSum(new long[]{+1, -1}) => -18446744073709551616 ...

c++,comparison,conditional-statements,integer-arithmetic

For the first one, to check if a number is a multiple of use: if (num % 10 == 0) // its divisible by 10 For the second one: if(((num - 1) / 10) % 2 == 1 && num <= 100) But that's rather dense, you might be better...

java,integer,integer-arithmetic

While == can be performed between two references (and is, when both sides are Integer), <= can't - so the compiler unboxes. So, your code is equivalent to: while (i.intValue() <= j.intValue() && j.intValue() <= i.intValue() && i != j) Now when i and j refer to different Integer objects...

math,random,expression,integer-arithmetic

I think a reasonable way to approach this is to start with a value for the total and recursively construct a random expression tree to reach that total. You can choose how many operators you want in each equation and ensure that all values are integers. Plus, you can choose...

A 12-digit number is already outside the boundaries of Int32, which means you just cannot do arithmetic with it in batch files directly. What you can do, is adding the numbers by digit, maintaining a carry, just as you did in primary school. It will be slower, but it works....

The type of the prims have changed since GHC 7.6.3. For example, comparison no longer results in a boolean. This means your isNeg# function should instead read: isNeg# :: Int# -> Int# isNeg# x = negateInt# (x <# 0#) This produces (7.8.2, -O2): _cMj: testq %r14,%r14 setl %al movzbl %al,%ebx...

algorithm,math,big-o,computer-science,integer-arithmetic

Edit: Your previous question shows that you are interested in the number of terms in the inner summation. The loop for j<- first to last has last-first+1 terms (this is easiest to see if you write down some examples with small last-first). So for (1), there are (2n-i)-(1)+1=2n-i terms for...

In theory, Haskell Integers are entirely unbounded, so there is no official way to get a largest one. In practice, GHC uses (usually) the GNU GMP library which allows not quite unbounded, but still enormous numbers, each single number taking up a significant part of your computer memory. In practice,...

math,overflow,guava,integer-arithmetic,underflow

As GregS wrote, If a and b are of opposite signs(*) then addition of them cannot possibly overflow. Now, if they're of the same sign, the sign of the result must be the same if there's mo overflow. (*) With zero and positive treated the same, which doesn't matter and...

c,integer-division,divide-by-zero,integer-arithmetic,ppc

Division by zero is undefined behaviour, see C11 standard 6.5.5#5 (final draft). Getting a trap or SIGFPE is just a courtesy of the CPU/OS. PowerPC as typical RISC CPU does not catch it, as it can safely be detected by a simple check of the divisor right before doing the...

java,math,arbitrary-precision,integer-arithmetic

Method 1 I came up with this method; it's not necessarily efficient, but it works. Notice that you can use the length of the input (in digits) to compute its logarithm. You can use this to perform division, and therefore modulus. Specifically, first notice that 849465603662254214335539562 / (578907659710377778063722 * 1000)...

math,floating-point,integer,floating-point-conversion,integer-arithmetic

pseudocode: n / pow(10, floor(log10(n))+1) ...

This might do the trick: public static void Main() { byte[] buf = new byte[] { 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; byte result = 0; foreach(var b in buf.Reverse()) { result <<= 1; if(b == 0xFF) result |= 1; } Console.WriteLine(result); } ...

c++,performance,int,integer-arithmetic,type-punning

Yes, it's a perfectly valid optimization when you're testing a signed integer and the lower bound is zero. In fact it's such a common optimization that your compiler will almost certainly do it automatically; obfuscating your code by doing it yourself is very likely to be a pointless premature optimization....

c,prolog,ffi,integer-arithmetic,sicstus-prolog

Use it something like this: SP_term_ref tr = ... some term ... int native = 0; // want portable, little endian size_t buf_size = 0; if (!SP_get_integer_bytes(tr, NULL, &buf_size, native) // if buf_size was updated, then there was not really an error && buf_size == 0) { { // Something...

casting,rust,integer-arithmetic

Yes, you can use as: let total: u64 = a as u64 + b as u64 + c as u64; More info on type casting: http://doc.rust-lang.org/reference.html#type-cast-expressions...

c++,performance,number-theory,integer-arithmetic,modular-arithmetic

You can satisfy for one i at a time while preserving all the ones already satisfied: step is the LCM of all the a[i] already satisfied (initially 1). y is the minimum value satisfying all the ones you did already. The key concept is that any Y satisfying all i...

algorithm,math,integer,average,integer-arithmetic

I think the first return expression is what you're after: def av(a,b): mi = min(a,b) ma = max(a,b) if ma - mi > 4: return (((mi + 8) + ma) / 2.) % 8 else: return (mi+ma)/2. mi is the minimum of the two; ma is the max....

c,math,largenumber,integer-arithmetic

The easiest thing you can do is to simply discard half of the hash and do modulo (simply using %) on the other half. The next simplest thing to do is to use an existing bignum library. If you want to use the whole hash, though, you need to do...