Questions tagged [integers]

For questions specifically about an integer data type in a programming language, including machine integers, big integers, and abstract notions like Church numerals

Filter by
Sorted by
Tagged with
11 votes
9 answers
5k views

Should bytes be signed?

I’m trying to decide whether my language should provide signed or unsigned bytes, but I’m struggling to find a good reason to choose either side. Popular languages vary in their decision. For example, ...
feldentm's user avatar
  • 1,749
5 votes
9 answers
1k views

Correctness of mixed signed/unsigned arithmetic

I'm implementing signed and unsigned integers in my language. They are represented in C as signed long and unsigned long ...
Matheus Moreira's user avatar
20 votes
10 answers
4k views

What are the drawbacks of allowing implicit boolean/integer conversions?

Some languages (C, C++, JavaScript, Python) allow one to use integers as booleans and vice versa: int x; if (x) // Equivalent to: x != 0 y(); Or: ...
user16217248's user avatar
  • 7,535
6 votes
1 answer
561 views

What, if any, runtime cost is incurred by using 64-bit ints on 32-bit platforms in LLVM?

I'm writing a language frontend for LLVM, and I noticed that the IR docs say that integers of (almost)any width can be used without limit. I presume this to mean that LLVM or its backends convert ...
Ginger's user avatar
  • 2,579
9 votes
8 answers
3k views

Invalid signed integer in C and similar languages

In C a signed integer is just a binary number and all binary numbers are valid integers. There is no NaN value. C uses 2s complement for signed integers meaning ...
John Rennie's user avatar
12 votes
8 answers
3k views

What are the advantages of having a set number of fixed sized integers versus defining the exact number of bits in every integer?

In most statically typed languages, integers are offered in 8-bit types and increasing powers of 2. However, C has a new keyword _BitInt which as I understand ...
user16217248's user avatar
  • 7,535
25 votes
6 answers
1k views

Why don't many languages have integer range types?

An integer range type like 0..100 means that a value can be any integer in that range. Arithmetic operations on range types produce other range types, for example ...
kaya3's user avatar
  • 17.3k
7 votes
2 answers
223 views

Why short and long and double and similar instead of unambigous width types such as int16 or int64 or float64?

Many languages have keywords short and int and long and ...
user16217248's user avatar
  • 7,535
24 votes
10 answers
1k views

What are some advantages/disadvantages of having built-in syntax to represent numbers in non-decimal bases?

(For this question, I'm referring to integers. This question also assumes the language still uses base two internally, even if to the programmer it appears as base ten - this question is about syntax)....
cocomac's user avatar
  • 575
7 votes
5 answers
448 views

Why are expressions in languages so prone to integer overflow?

I've always wondered. Why do major languages let their addition and multiplication operators be so prone to integer overflow? My programming language would have separate operators to handle overflow. ...
Dannyu NDos's user avatar