Programming Search⌘K

Conceptcore

Numeric type

Also called number type, numeric types, arithmetic type, integer type, floating-point type, decimal type, complex type, bignum, numerical tower.

A numeric type holds numbers of one kind, such as integers, floating-point numbers, decimals or complex numbers. Its range, its precision and its rules for division and mixing differ by language.

Applies to
core-languages

Idea

A program counts things, measures things and computes money. Each of these needs numbers, but a computer has no single kind of number. A numeric type is one kind of number that a language gives: an integer type for whole numbers, a floating-point type for approximate real numbers, and in some languages decimal, rational, complex and unlimited integer types. The type decides which values exist, how exact they are, and what / does.

from decimal import Decimal
from fractions import Fraction

# Python has three built-in numeric types, and the library adds two more.
for v in (7, 7.5, 7 + 2j, Fraction(15, 2), Decimal("7.5")):
    print(type(v).__name__, v)

# Mixed arithmetic widens the narrower operand: int to float to complex.
print(type(1 + 2.0).__name__, type(2.0 + 1j).__name__)

# / always gives a float, and // gives the floor.
print(7 / 2, 7 // 2, -7 // 2, 7.0 // 2)

# An int has no fixed width, but a float keeps only 53 bits.
print(2**64, float(2**53 + 1) == 2**53)

# A binary float cannot hold 0.1 exactly, but Decimal and Fraction can.
print(0.1 + 0.2, Decimal("0.1") + Decimal("0.2"), Fraction(1, 10) + Fraction(2, 10))
Output
int 7
float 7.5
complex (7+2j)
Fraction 15/2
Decimal 7.5
float complex
3.5 3 -4 3.0
18446744073709551616 True
0.30000000000000004 0.3 3/10

The same value 7 or 7.5 has a different type in each line, and the type controls the result. Adding an int to a float gives a float. / gives a float even for two integers, and // rounds down, so -7 // 2 is -4. The int 2 to the power 64 is exact, but a float cannot tell 2 to the power 53 from the next integer. 0.1 + 0.2 is not exactly 0.3 in binary floating point, but it is in Decimal and Fraction.

How it works

Kinds of numeric type. The Go specification says that "An integer, floating-point, or complex type represents the set of integer, floating-point, or complex values, respectively. They are collectively called numeric types"1. Python has "three distinct numeric types: integers, floating-point numbers, and complex numbers"2, and its library adds rationals and decimals. Java has "the integral types byte, short, int, long, and char, and the floating-point types float and double"3. The main kinds are:

  • Fixed-width integers, such as int32 or u8. They are exact, but they hold only a range of values. See integer representation.
  • Floating-point numbers, such as double or f64. They cover a very large range, but they keep about 15 to 17 decimal digits. See floating-point arithmetic.
  • Unlimited integers, such as Python int, JavaScript BigInt, Java BigInteger and Go big.Int. They grow as needed, so they do not overflow, but each operation costs more.
  • Decimal types, such as C# decimal, Java BigDecimal and Python Decimal. They store base-10 digits, so 0.1 is exact.
  • Rationals and complex numbers, such as Python Fraction, Go big.Rat, Go complex128 and C double complex.

Range and width. A fixed-width type has a size that the language either fixes or leaves to the platform. Java, C#, Go and Rust fix the size of most types. C does not: int "is guaranteed to be at least 16 bits. Most current systems use 32 bits"4. Each language also has a type with the size of a pointer for indexes and sizes. In Rust, "The usize type is an unsigned integer type with the same number of bits as the platform's pointer type"5.

Literals. A literal gets a type from its form. In most languages 7 is an integer and 7.0 is a floating-point number. A suffix chooses another type: 7L in Java, 7u8 in Rust, 7n for a JavaScript BigInt and 0.1m for a C# decimal.

Mixing types. When an operator has two operands of different numeric types, the language either converts one of them or rejects the expression. Python "fully supports mixed arithmetic"2: it widens the narrower operand from int to float to complex. C, C++, Java and C# have promotion rules, so byte + byte is an int in Java and int + double is a double. Go and Rust do not convert. In Go, "Explicit conversions are required when different numeric types are mixed in an expression or assignment"1. A JavaScript BigInt "cannot be mixed with a Number value in operations; they must be coerced to the same type"6.

Division. Integer division is where the types differ most. C, C++, Java, C#, Go and Rust truncate toward zero, so -7 / 2 is -3 and -7 % 2 is -1. Python // rounds toward minus infinity, so -7 // 2 is -4 and -7 % 2 is 1. JavaScript has no integer type for ordinary numbers: "The JavaScript Number type is a double-precision 64-bit binary format IEEE 754 value"7, so 7 / 2 is 3.5. Integer division by zero is an error in most languages, but floating-point division by zero gives infinity or NaN.

Overflow. A fixed-width integer has a largest value. Java says that "The integer operators do not indicate overflow or underflow in any way"3, so int arithmetic wraps. Rust panics in a debug build, C# throws in a checked context, and signed overflow in C and C++ is undefined behavior. See integer overflow.

In languages

LanguageVerdictNote
PythonNative
C++Native
JavaNative
CNative
C#Native
JavaScriptNative
TypeScriptNativeTypeScript has the types number and bigint, which are the two numeric types of JavaScript, and the compiler rejects arithmetic that mixes them. No example file exists.
GoNative
RustNative
KotlinNativeKotlin has Byte, Short, Int and Long, the unsigned types UInt and ULong, and Float and Double. It does not widen a number to another type in an assignment, so the program calls a conversion such as toLong(). No example file exists because kotlinc is not installed.
SQLNativeSQL has exact numeric types, such as INTEGER, BIGINT and DECIMAL(p, s), and approximate types, such as REAL and DOUBLE PRECISION. DECIMAL is the usual type for money. No example file exists.
BashIdiomBash arithmetic in $(( )) works on signed integers of a fixed width, and integer division truncates. Bash has no floating-point arithmetic, so scripts use bc or awk for fractions. No example file exists.
PowerShellNativePowerShell uses the .NET numeric types, such as [int], [long], [double], [decimal] and [bigint], and it converts the operands of mixed arithmetic to a common type. No example file exists because pwsh is not installed.
HTMLIdiomAn input element with type number accepts only numbers and has the attributes min, max and step, but the value that a script reads is a string.
CSSIdiomCSS values have types such as number, integer, length and percentage, and calc() does arithmetic on them, but CSS has no variables of a numeric type in the sense of a program.
Regular expressionsDoes not applyA regular expression matches digits as characters, and it has no numeric values or arithmetic.
Language Verdict Mechanism
Python native int with no limit, float, complex; Fraction and Decimal in the library
JavaScript native number, a 64-bit float, and bigint for exact integers
TypeScript native number and bigint, the same values as JavaScript
Java native byte, short, int, long, char, float, double; BigInteger and BigDecimal
Kotlin native Byte to Long, unsigned UInt and ULong, Float, Double; no implicit widening
C# native signed and unsigned integers to 128 bits, float, double, decimal, BigInteger
Go native int8 to int64, uint8 to uint64, float32, float64, complex128; exact untyped constants
Rust native i8 to i128, u8 to u128, isize, usize, f32, f64
C native char to long long with platform sizes, float, double, long double, complex types
C++ native the types of C, numeric_limits, and concepts such as std::integral
Bash idiom integer arithmetic in $(( )) on 64-bit signed integers; no floating point without bc or awk
PowerShell native the .NET types [int], [long], [double], [decimal] and [bigint]
SQL native INTEGER, BIGINT, DECIMAL(p, s), NUMERIC, REAL and DOUBLE PRECISION
Regex n/a a pattern matches digits as text, but it has no numbers
HTML idiom <input type="number"> accepts numbers, but the value is a string
CSS idiom properties take numbers, integers, lengths and percentages, and calc() computes with them

Every general-purpose language has integer and floating-point types. They differ in whether integers have a limit, in the rules for mixing types, in the rounding of integer division, and in what happens on overflow.

The example files show these differences. Python shows the numbers tower, the rounding of int(), // and round(), and an exact 100 factorial. JavaScript shows that number is exact only up to 2 to the power 53, that it has no integer division, and that BigInt and number do not mix. Java shows truncating division, promotion of byte to int, an int product that wraps before it becomes a long, and BigDecimal. C# shows decimal, the fixed sizes and literal suffixes. Go shows that int32 and int need a conversion, exact untyped constants, complex numbers and math/big. Rust shows the default types i32 and f64, div_euclid and checked_add. C shows the platform sizes, promotion of unsigned char to int and a float that cannot hold 16777217. C++ shows a template limited to numeric types by a concept, numeric_limits and std::midpoint.

PythonGitHub
import math
import numbers
import sys

# The numbers module is a tower: every Integral is Rational, every Rational is Real.
print(isinstance(3, numbers.Rational), isinstance(3.0, numbers.Rational), isinstance(3.0, numbers.Real), isinstance(1j, numbers.Real))

# Conversion to int truncates toward zero, but // and divmod round toward minus infinity.
print(int(3.9), int(-3.9), -7 // 2, divmod(-7, 2), math.fmod(-7, 2))

# round() rounds a tie to the even neighbor.
print(round(0.5), round(1.5), round(2.5))

# float has infinities and NaN, and NaN is not equal to itself.
inf, nan = float("inf"), float("nan")
print(inf > sys.float_info.max, nan == nan, math.isnan(nan))

# An int grows as needed, so 100 factorial is exact.
f = math.factorial(100)
print(f.bit_length(), str(f)[:12], len(str(f)))

# A float that is too big for an int conversion is still exact as an int.
print(int(1e20), 10**20 == 1e20, 10**23 == 1e23)
Output
True False True False
3 -3 -4 (-4, 1) -1.0
0 2 2
True False True
525 933262154439 158
100000000000000000000 True False
  • Verdict: native. The numbers module is a tower, so 3 is Rational and 3.0 is Real but not Rational. int() truncates toward zero, but // and divmod round toward minus infinity, and round() takes a tie to the even neighbor, so round(2.5) is 2. NaN is not equal to itself. An int has no limit, so 100 factorial is exact with 158 digits. 10**20 == 1e20 is true, but 10**23 == 1e23 is false, because 1e23 has no exact binary form.
#include <concepts>
#include <limits>
#include <numbers>
#include <numeric>
#include <print>
#include <type_traits>

// A concept limits a template to numeric types.
template <typename T>
    requires std::integral<T> || std::floating_point<T>
T half(T x) { return x / 2; }

int main() {
    // The same template gives integer division for int and real division for double.
    std::println("{} {} {}", half(7), half(7.0), half(-7));

    // short + short has type int, because of integer promotion.
    short s = 1;
    std::println("{} {}", std::is_same_v<decltype(s + s), int>, std::is_same_v<decltype(1 + 1.0f), float>);

    // numeric_limits describes each type.
    std::println("{} {} {} {}", std::numeric_limits<int>::max(), std::numeric_limits<double>::digits,
                 std::numeric_limits<unsigned>::is_signed, std::numeric_limits<float>::has_infinity);

    // std::midpoint does not overflow, unlike (a + b) / 2.
    int a = std::numeric_limits<int>::max() - 2, b = std::numeric_limits<int>::max();
    std::println("{}", std::midpoint(a, b));

    // Mathematical constants are typed.
    std::println("{:.5f} {:.5f}", std::numbers::pi_v<float>, std::numbers::e);
}
Output
3 3.5 -3
true true
2147483647 53 false true
2147483646
3.14159 2.71828
  • Verdict: native. A template limited by the concepts std::integral and std::floating_point does integer division for int and real division for double. decltype shows that short + short is an int. std::numeric_limits gives the range of int and the 53 bits of a double. std::midpoint of two large int values does not overflow. <numbers> gives typed constants such as pi_v<float>.
JavaGitHub
import java.math.BigDecimal;
import java.math.BigInteger;

public class Main {
    public static void main(String[] args) {
        // Integer division truncates, and % takes the sign of the dividend.
        System.out.println((7 / 2) + " " + (-7 / 2) + " " + (-7 % 2) + " " + Math.floorDiv(-7, 2) + " " + Math.floorMod(-7, 2));

        // Arithmetic on byte, short and char promotes the operands to int.
        byte a = 100, b = 100;
        int sum = a + b;
        byte wrapped = (byte) (a + b);
        System.out.println(sum + " " + wrapped + " " + ('A' + 1) + " " + (char) ('A' + 1));

        // int times int is an int, even when the result is stored in a long.
        int big = 1_000_000;
        long wrong = big * big;
        long right = (long) big * big;
        System.out.println(wrong + " " + right);

        // Integer division by zero throws, but floating-point division gives Infinity.
        try {
            System.out.println(1 / (big - big));
        } catch (ArithmeticException e) {
            System.out.println("ArithmeticException " + (1.0 / 0) + " " + (0.0 / 0));
        }

        // BigInteger and BigDecimal are classes for exact arithmetic.
        BigInteger f = BigInteger.ONE;
        for (int i = 2; i <= 30; i++) f = f.multiply(BigInteger.valueOf(i));
        System.out.println(f + " " + (0.1 + 0.2) + " " + new BigDecimal("0.1").add(new BigDecimal("0.2")));

        // The ranges come from the wrapper classes.
        System.out.println(Integer.MAX_VALUE + " " + Long.MAX_VALUE + " " + Double.MAX_VALUE);
    }
}
Output
3 -3 -1 -4 1
200 -56 66 B
-727379968 1000000000000
ArithmeticException Infinity NaN
265252859812191058636308480000000 0.30000000000000004 0.3
2147483647 9223372036854775807 1.7976931348623157E308
  • Verdict: native. / truncates and % takes the sign of the dividend, and Math.floorDiv and Math.floorMod round down. Arithmetic on byte and char gives an int, so a + b is 200 and the cast to byte gives -56. big * big wraps as an int before it is stored in a long. Integer division by zero throws ArithmeticException, and 1.0 / 0 is Infinity. BigInteger and BigDecimal give exact results.
#include <complex.h>
#include <limits.h>
#include <stdio.h>

int main(void) {
    /* The sizes are set by the platform; this is a 64-bit system. */
    printf("%zu %zu %zu %zu %d\n", sizeof(short), sizeof(int), sizeof(long), sizeof(long long), INT_MAX);

    /* Integer division truncates, and % takes the sign of the dividend. */
    int n = 7, m = -7;
    printf("%d %d %d %.1f\n", n / 2, m / 2, m % 2, n / 2.0);

    /* Operands smaller than int are promoted to int before the arithmetic. */
    unsigned char a = 200, b = 100;
    printf("%d %zu\n", a + b, sizeof(a + b));

    /* 5 / 2 is an int, so the order of the operations matters. */
    printf("%.1f %.1f\n", n / 2 * 2.0, n / 2.0 * 2);

    /* A float keeps 24 bits, so 16777217 becomes 16777216. */
    int big = 16777217;
    float f = (float)big;
    printf("%.1f\n", f);

    /* C has complex types. */
    double complex z = 3.0 + 4.0 * I;
    printf("%.1f %.1f %.1f\n", creal(z), cimag(z), cabs(z));
    return 0;
}
Output
2 4 8 8 2147483647
3 -3 -1 3.5
300 4
6.0 7.0
16777216.0
3.0 4.0 5.0
  • Verdict: native. The sizes of short, int, long and long long come from the platform, here 2, 4, 8 and 8 bytes. / truncates. Two unsigned char values are promoted to int before the addition, so the sum is 300 and has the size of an int. 7 / 2 * 2.0 is 6.0, but 7 / 2.0 * 2 is 7.0. A float keeps 24 bits, so 16777217 becomes 16777216. double complex is part of the language.
using System.Numerics;

// Integer division truncates, and % takes the sign of the dividend.
Console.WriteLine($"{7 / 2} {-7 / 2} {-7 % 2} {7 / 2.0}");

// decimal is a base-10 type, so 0.1 is exact.
Console.WriteLine($"{0.1 + 0.2} {0.1m + 0.2m} {0.1 + 0.2 == 0.3} {0.1m + 0.2m == 0.3m}");

// double division by zero gives infinity, but int and decimal division throw.
int zero = 0;
Console.WriteLine($"{double.IsPositiveInfinity(1.0 / zero)} {double.IsNaN(0.0 / zero)}");
try { Console.WriteLine(1m / zero); } catch (DivideByZeroException) { Console.WriteLine("DivideByZeroException"); }

// The sizes of the types are fixed, except nint, which has the size of a pointer.
Console.WriteLine($"{sizeof(int)} {sizeof(long)} {sizeof(decimal)} {sizeof(double)} {Int128.MaxValue}");

// BigInteger has no limit.
BigInteger f = 1;
for (int i = 2; i <= 30; i++) f *= i;
Console.WriteLine(f);

// A literal suffix chooses the type.
var values = new object[] { 1, 1L, 1u, 1.0, 1f, 1m };
Console.WriteLine(string.Join(" ", values.Select(v => v.GetType().Name)));
Output
3 -3 -1 3.5
0.30000000000000004 0.3 False True
True True
DivideByZeroException
4 8 16 8 170141183460469231731687303715884105727
265252859812191058636308480000000
Int32 Int64 UInt32 Double Single Decimal
  • Verdict: native. / truncates for integers. decimal is a base-10 type, so 0.1m + 0.2m == 0.3m is true, and 0.1 + 0.2 == 0.3 is false for double. double division by zero gives infinity, but decimal division by zero throws DivideByZeroException. The sizes are fixed: int is 4 bytes, long is 8 and decimal is 16, and Int128 and BigInteger hold larger values. A literal suffix chooses the type.
JavaScriptGitHub
// A JavaScript number is a 64-bit float, so there is one numeric type for both 7 and 7.5.
console.log(typeof 7, typeof 7.5, Number.isInteger(7.0), 7 / 2);

// Integers are exact only up to 2**53 - 1.
console.log(Number.MAX_SAFE_INTEGER, 2 ** 53 === 2 ** 53 + 1, Number.isSafeInteger(2 ** 53));

// There is no integer division; use Math.trunc or Math.floor. % takes the sign of the dividend.
console.log(Math.trunc(-7 / 2), Math.floor(-7 / 2), -7 % 2);

// Division by zero gives Infinity or NaN, not an error.
console.log(1 / 0, -1 / 0, 0 / 0, Number.isNaN(0 / 0));

// BigInt is the second numeric type: exact integers of any size.
console.log(typeof 1n, 2n ** 64n, 7n / 2n, -7n / 2n);

// A BigInt and a number do not mix in arithmetic.
try {
  console.log(1n + 1);
} catch (e) {
  console.log(e.name);
}
console.log(1n + BigInt(1), Number(2n ** 53n) + 1, 1n < 2, 2n == 2);

// 0.1 has no exact binary form.
console.log(0.1 + 0.2, (0.1 + 0.2).toFixed(2), 0.1 + 0.2 === 0.3);
Output
number number true 3.5
9007199254740991 true false
-3 -4 -1
Infinity -Infinity NaN true
bigint 18446744073709551616n 3n -3n
TypeError
2n 9007199254740992 true true
0.30000000000000004 0.30 false
  • Verdict: native. typeof gives "number" for both 7 and 7.5, and 7 / 2 is 3.5. Integers are exact only up to Number.MAX_SAFE_INTEGER, so 2 ** 53 === 2 ** 53 + 1 is true. Integer division needs Math.trunc or Math.floor. Division by zero gives Infinity or NaN. BigInt is exact, and 7n / 2n truncates to 3n. 1n + 1 throws TypeError, but comparisons such as 1n < 2 work.
package main

import (
	"fmt"
	"math"
	"math/big"
	"math/cmplx"
)

func main() {
	// Integer division truncates, and % takes the sign of the dividend.
	fmt.Println(7/2, -7/2, -7%2, 7.0/2)

	// Numeric types do not mix: int32 + int does not compile, so convert.
	var a int32 = 5
	var b int = 7
	fmt.Println(int(a)+b, float64(b)/2)

	// Untyped constants are exact, and they get a type only where they are used.
	const huge = 1 << 100
	fmt.Println(huge>>98, math.MaxInt64, math.MaxUint32)

	// A complex type is built in.
	fmt.Println(cmplx.Sqrt(-1), real(3+4i), cmplx.Abs(3+4i))

	// Floating-point division by zero gives infinity at run time.
	zero := 0.0
	fmt.Println(1/zero, math.IsNaN(zero/zero))

	// math/big gives exact integers and rationals.
	f := new(big.Int).MulRange(1, 30)
	r := new(big.Rat).Add(big.NewRat(1, 10), big.NewRat(2, 10))
	fmt.Println(f, r, 0.1+0.2 == 0.3)
}
Output
3 -3 -1 3.5
12 3.5
4 9223372036854775807 4294967295
(0+1i) 3 5
+Inf true
265252859812191058636308480000000 3/10 true
  • Verdict: native. / truncates for integers, and 7.0/2 is 3.5. int32 and int are different types, so the program converts before it adds them. Untyped constants are exact, so 1 << 100 is a valid constant, and 0.1+0.2 == 0.3 is true because all three values are constants. complex128 is built in. math/big gives exact integers and rationals.
RustGitHub
fn main() {
    // An integer literal is i32 and a float literal is f64, unless a suffix or a type says otherwise.
    let a = 7;
    let b = 7.0;
    let c = 7u8;
    println!("{} {} {} {}", a / 2, b / 2.0, c / 2, -7 / 2);

    // / and % truncate; div_euclid and rem_euclid give a remainder that is not negative.
    println!("{} {} {} {}", -7 % 2, (-7i32).div_euclid(2), (-7i32).rem_euclid(2), 7.5f64.div_euclid(2.0));

    // Numeric types do not mix: i32 + i64 does not compile, so convert.
    let x: i32 = 5;
    let y: i64 = 7;
    println!("{} {} {}", i64::from(x) + y, x as f64 / 2.0, u8::try_from(300).is_err());

    // Each type has its range, and the checked methods return None on overflow.
    println!("{} {} {:?}", i32::MAX, u64::MAX, i32::MAX.checked_add(1));

    // usize has the size of a pointer.
    println!("{} {} {}", size_of::<usize>(), size_of::<i128>(), size_of::<f32>());

    // Floating-point division by zero gives infinity, and NaN is not equal to itself.
    let zero = 0.0f64;
    println!("{} {} {}", 1.0 / zero, (zero / zero).is_nan(), 0.1 + 0.2);
}
Output
3 3.5 3 -3
-1 -4 1 3
12 2.5 true
2147483647 18446744073709551615 None
8 16 4
inf true 0.30000000000000004
  • Verdict: native. A literal with no suffix is i32 or f64. / and % truncate, and div_euclid and rem_euclid round so that the remainder is not negative. i32 and i64 do not mix, so the program uses i64::from, and u8::try_from(300) fails. checked_add returns None at i32::MAX. usize has the size of a pointer. Floating-point division by zero gives inf.
  • The numerical tower. Scheme puts its numeric types in a hierarchy, so that "every integer is a rational with an implicit denominator of 1, and all reals are complex with an implicit imaginary part of 0"8. A conversion up the tower is safe, because "coercing an integer to a rational loses no information"8. The Python numbers module "defines a hierarchy of numeric abstract base classes which progressively define more operations"9.
  • Exact constants. Go computes constant expressions exactly, so 1 << 100 is a valid constant and 0.1+0.2 == 0.3 is true when all three values are constants. The value gets a fixed type only where the program uses it.
  • Generic numeric code. C++ concepts such as std::integral, Rust traits and C# generic math let one function work for many numeric types.
  • Units. A number that has a unit, such as metres, can have its own type, so that a program cannot add metres to seconds.

Pitfalls

  • Floats for money. 0.1 + 0.2 is 0.30000000000000004 in binary floating point. Use a decimal type or an integer number of cents. C# says that "The decimal type is appropriate when the required degree of precision is determined by the number of digits to the right of the decimal point"10.
  • Overflow before widening. In Java, long x = big * big multiplies two int values and wraps before the result becomes a long. Convert one operand first.
  • Negative division. Code that ports from Python to C or Java gets a different result for -7 / 2 and -7 % 2. Use Math.floorDiv in Java or div_euclid in Rust when the rounding must go down.
  • Large integers in JavaScript. An integer above 2 to the power 53 loses digits in a number. IDs from a database or JSON can change value. Keep them as strings or as BigInt.
  • Platform sizes. In C, long is 32 bits on 64-bit Windows and 64 bits on 64-bit Linux and macOS. Use the types of <stdint.h> when the size matters.
  • Integer division where a fraction is meant. 7 / 2 * 2.0 is 6.0 in C, because 7 / 2 is the integer 3.

Cost

Fixed-width integer and floating-point operations map to machine instructions, so most of them take one or a few cycles. Division costs more than multiplication. Unlimited integers, decimals and rationals are done in software, and the time of an operation grows with the number of digits. A wider type uses more memory and more cache, which matters in large arrays.

History

The first FORTRAN manual of 1956 had two numeric types. It said that "Two types of constant are permissible: fixed point (restricted to integers) and floating point (characterized by being written with a decimal point)"11. For variables, "Fixed point variables are distinguished by the fact that their first character is I, J, K, L, M, or N"11. That rule is why many programs still use i, j and n as names of integers.

Integer types of many sizes followed, because machines had words of many sizes. Wikipedia says that an integer type is "a data type that represents some range of mathematical integers" and that "Integral data types may be of different sizes and may or may not be allowed to contain negative values"12. Scheme made the hierarchy of numeric types part of the language as the numerical tower8. Python has an int with "unlimited precision"2, and JavaScript added BigInt because "BigInt values represent integer values which are too high or too low to be represented by the number primitive"6.

References

  1. The Go Programming Language Specification, Numeric types
  2. Built-in Types, Python documentation, Numeric Types - int, float, complex
  3. The Java Language Specification, Java SE 25 Edition, Chapter 4, 4.2 Primitive Types and Values; 4.2.2 Integer Operations
  4. Arithmetic types, C reference, cppreference.com, Integer types; Data models
  5. Numeric types, The Rust Reference, Machine-dependent integer types
  6. BigInt, MDN Web Docs, Description
  7. Number, MDN Web Docs, Number encoding
  8. Numerical tower, Wikipedia, Introduction; In Scheme
  9. numbers, Numeric abstract base classes, Python documentation, Introduction
  10. Floating-point numeric types, C# language reference, Characteristics of the floating-point types
  11. The FORTRAN Automatic Coding System for the IBM 704 EDPM, Programmer's Reference Manual, 1956, Chapter 2, Constants and Variables
  12. Integer (computer science), Wikipedia, Introduction

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/VTXJS0/text.yaml