Skip to main content

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

14 votes
3 answers
1k views

When can widening conversions cause problems?

I can understand the reason for raising a warning or error when you try to convert a wider integer type to a narrower one, due to the loss of precision. Some C compilers will warn about this: ...
CPlus's user avatar
  • 8,793
12 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,969
5 votes
9 answers
2k 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
5k 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: ...
CPlus's user avatar
  • 8,793
6 votes
1 answer
600 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,629
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 ...
CPlus's user avatar
  • 8,793
26 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
  • 20k
7 votes
2 answers
245 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 ...
CPlus's user avatar
  • 8,793
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
478 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