# A Beginner's Guide to D/The Basics/Types and Math

Jump to navigation Jump to search

## What are types?

If you look directly at the contents of a computer's memory, you see only a lot of bytes. These are often shown as numbers but in fact they don't have a meaning on its own, not even the meaning of a number.

Types are used in computer languages like D or C to give one byte or a sequence of bytes a meaning. Types define if these bytes are a number, a text, a date or whatever.

## The Basic Types

Two basic types have already been introduced: int and float, for non-decimal and decimal numbers, respectively. Here, all of the basic types are introduced, including limits on their values and how large they are in memory.

 Type What it Is Lower Limit Upper Limit Storage Size byte A very small, integer number. -128 127 8 bits (1 byte) ubyte A very small, integer, non-negative number. 0 255 8 bits (1 byte) short A small, integer number. -32768 32767 16 bits (2 bytes) ushort A small, integer, non-negative number. 0 65535 16 bits (2 bytes) int A integer number. -2147483648 2147483647 32 bits (4 bytes) uint A integer, non-negative number. 0 4294967296 32 bits (4 bytes) long A potentially huge, integer number. -9223372036854775808 9223372036854775807 64 bits (8 bytes) ulong A potentially huge, integer, non-negative number. 0 18446744073709551616 64 bits (8 bytes) float A number. About -3.4e38 About 3.4e38 32 bits (4 bytes) ifloat An imaginary number. About -3.4e38i About 3.4e38i 32 bits (4 bytes) double A potentially huge number. About -1.8e308 About 1.8e308 64 bits (8 bytes) idouble A potentially huge number imaginary number. About -1.8e308i About 1.8e308i 64 bits (8 bytes) real A potentially gigantic number. The maximum size of decimal number that the computer is capable of supporting on the processor. Only generally defined as larger than double on x86 processors. (On x86) About -5.9e4436 (On x86) About 5.9e4436 (On x86) 80 bits (10 bytes) ireal A potentially gigantic imaginary number. (On x86) About -5.9e4436 (On x86) About 5.9e4436 (On x86) 80 bits (10 bytes) char A single element of text. Usually used for displayable, printable text, but can technically be used for anything that will fit. 'a', '0', '.', '+', ' ' are all valid chars. There are several ways to encode a character to a char, this type uses the UTF-8 encoding that encodes the most used characters with a smaller size. 0 255 8 bits (1 byte) wchar A single element of text encoded as UTF-16. If you are not sure what this means use 'char'. 0 65535 16 bits (2 byte) dchar A single element of text encoded as UTF-32. If you are not sure what this means use 'char'. 0 (not a displayable text element) 4294967296 32 bits (4 byte)