Questions tagged [integer]

Common datatype in many programming languages for representing both negative and non-negative whole numbers. Use this tag for questions about using, storing, or manipulating integers. For 64-bit integers, use the [long-integer] tag instead.

An integer is a whole number that can be negative, positive, or zero. For example, -2, -1, 0, 1, 2. In many programming languages, the integer data type is commonly represented as 32-bits, but may also be 64-bits (Usually referred to as the Long data type).

For 32-bit integers:

  • The signed range is : -2147483648 to 2147483647.
  • The unsigned range is : 0 to 4294967295.

For 64-bit integers:

  • The signed range is : -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
  • The unsigned range is : 0 to 18,446,744,073,709,551,615.

For further reading, see the Wikipedia article on integers.

13448 questions
5
votes
0 answers

Is it possible to get a performance advantage by using integers in R?

In R, an advantage of using integers over doubles is object size. I'm somewhat surprized not to find such an advatage in performance. My naive expectation was that operating with less information would be more efficient. My work does a lot of number…
rluech
  • 606
  • 4
  • 15
5
votes
4 answers

Reliable overflow detection of floating-point/integer type conversion

Is there a safe way to reliably determine if an integral type T can store a floating-point integer value f (so f == floor(f)) without any overflow? Keep in mind that there is no guarantee that the floating point type F is IEC 559 (IEEE 754)…
plasmacel
  • 8,183
  • 7
  • 53
  • 101
5
votes
1 answer

Cartesian product of two int arrays using Java 8 streams

I have two arrays of int, a = {10,20,30} and {1,2,3}. I would like to get the Cartesian product of these two arrays. When I use List of Integers the logic works fine: List intList = Arrays.asList(10,20,30); List intList1…
jegadeesh
  • 109
  • 2
  • 8
5
votes
2 answers

Calculating an *integer* binomial coefficient in R

The number of ways of choosing k objects from n, i.e. the binomial coefficient n!/(k!(n-k)!), is an integer when n and k are integers. How can I calculate this guaranteeing that the result is both correct and of integer type? The choose function…
ChrisW
  • 1,265
  • 12
  • 12
5
votes
2 answers

Recursive algorithm stops working after certain depth

I was exploring Fork/Join framework and its possible speed benefits through factorial counting, when discovered that my sequential recursive algorithm breaks at a certain point. To be precise, when I try to count 46342! the result from…
Leonid Bor
  • 2,064
  • 6
  • 27
  • 47
5
votes
2 answers

How to handle NaNs in pandas dataframe integer column to postgresql database

I have a pandas dataframe with a "year" column. However some rows have a np.NaN value due to an outer merge. The data type of the column in pandas is therefore converted to float64 instead of integer (integer cannot store NaNs?). Next, I want to…
Rutger Hofste
  • 4,073
  • 3
  • 33
  • 44
5
votes
2 answers

Java syntax array {1,2,3} vs new int[] {1,2,3}

There's something I don't understand with array syntax. For example I can do that : int[] tab = {1,2,3}; Let's say I have a method that takes an array as a parameter, I can do that: myMethod(tab); But why can't I do that: myMethod({1,2,3}) Why do I…
AntonBoarf
  • 1,239
  • 15
  • 31
5
votes
2 answers

Integer division using only addition, multiplication, subtraction and maximum

Suppose we have a programming language ℤ which has the following syntax: ℤ := 0 | 1 | (+ ℤ ℤ) | (* ℤ ℤ) | (- ℤ ℤ) | (max ℤ ℤ) For convenience, we can define new binding forms in our language as follows: (not x) = (- 1 x) (abs x) = (- (max 0 (+ x…
Aadit M Shah
  • 72,912
  • 30
  • 168
  • 299
5
votes
4 answers

Java check if first digit of int is 0

So the question is very simple. How to check in java if first digit of an int is 0; Say I have: int y = 0123; int n = 123; Now I need an if statement that would return true for y and false for n.
Freddy19
  • 167
  • 4
  • 10
5
votes
16 answers

Roman to Integer in JS why it only convert the first character

I try to solve the Leedcode question 13 and the question is Given a roman numeral, convert it to an integer.(Input is guaranteed to be within the range from 1 to 3999.) This is my code below, I wonder why it only converts the first character in the…
cece
  • 67
  • 1
  • 1
  • 5
5
votes
3 answers

Erlang - Random Number gen with Makeref

I am trying to generate a random enough number quickly. Right Now I am using the following: uniqueID() -> C = random:uniform(9999) , %%%DO SPEED TEST random:seed(C,random:uniform(99),random:uniform(99)), {_, {H, Min, S}} =…
BAR
  • 15,909
  • 27
  • 97
  • 185
5
votes
4 answers

NSInteger types

I would like to know what is the differecnce between Integer 16, Integer 32 and Integer 64, and the difference between a signed integer and an unsigned integer(NSInteger and NSUInteger)
Skullhouseapps
  • 498
  • 1
  • 7
  • 14
5
votes
1 answer

r data.table avoid class discrepancy between RHS and LHS

I have a data set containing some groups and I want to calculate the number of records in each group, where a certain condition is met. I then want to expand the result to the rest of the records within each group (i.e. where the condition is not…
Amy M
  • 967
  • 1
  • 9
  • 19
5
votes
2 answers

Check if the sum of two unsigned ints is larger than uint_max

Suppose I have two integers x and y, and I want to check whether their sum is larger than UINT_MAX. #define UINT64T_MAX std::numeric_limits::max() uint64_t x = foo(); uint64_t y = foo(); bool carry = UINT64T_MAX - x < y; That code will…
jcarpenter2
  • 5,312
  • 4
  • 22
  • 49
5
votes
7 answers

Dividing integers

I know when dividing integers the default way it works is to discard the fractional part. E.g., int i, n, calls = 0; n = 1; n /= 3; printf("N = %i\n", n); for (i = 1; i > 0; i /= 3) { calls++; } printf("Calls = %i\n", calls); The code above…
Radek Simko
  • 15,886
  • 17
  • 69
  • 107