Data Types#
Integers#
Data Type |
Bit Size |
Value Range |
|---|---|---|
int8 |
8-bit |
-128 to 127 |
int16 |
16-bit |
-32,768 to 32,767 |
int32 |
32-bit |
-2,147,483,648 to 2,147,483,647 |
int64 |
64-bit |
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
Unsigned Integers (Only Positive Values)#
Data Type |
Bit Size |
Value Range |
|---|---|---|
uint8 |
8-bit |
0 to 255 |
uint16 |
16-bit |
0 to 65,535 |
uint32 |
32-bit |
0 to 4,294,967,295 |
uint64 |
64-bit |
0 to 18,446,744,073,709,551,615 |
Floating-Points#
Data Type |
Bit Size |
Value Range (Approximate) |
|---|---|---|
float16 |
16-bit |
±6.1 × 10⁻⁵ to ±65,504 |
float32 |
32-bit |
±1.2 × 10⁻³⁸ to ±3.4 × 10³⁸ |
float64 |
64-bit |
±2.2 × 10⁻³⁰⁸ to ±1.8 × 10³⁰⁸ |
These are approximate; some numbers might be represented more precisely, while others less so, depending on their exact binary representation.
float32 has about 7 decimal digits of precision.
float64 has about 15–17 decimal digits of precision.
Terms#
Significand is the part of a floating-point number that contains its significant digits.
Machine epsilon is the smallest positive number that, when added to 1.0, results in a number distinguishable from 1.0:
float32 (single precision): The machine epsilon is approximately 1.1920929e-07.
float64 (double precision): The machine epsilon is approximately 2.220446049250313e-16.
float32 example:
1.0 + 1.1920929e-07, you’ll get a value that is slightly greater than 1.0.
1.0 + (a number smaller than 1.1920929e-07) might still result in 1.0.
import numpy as np
print(np.array(1, dtype='float32') + np.array(1.1920929e-07, dtype='float32'))
print(np.array(1, dtype='float32') + np.array(1e-08, dtype='float32'))
1.0000001
1.0