HOWTO · Python
How to Find Maximum Float Value in Python
Find Python’s largest finite built-in float with sys.float_info.max, or get the maximum for a NumPy floating-point dtype with numpy.finfo().
On this page
On the runtime shown in this example, Python’s built-in float type has a largest finite value of 1.7976931348623157e+308. Use sys.float_info.max to retrieve the limit for your own runtime. If your code uses NumPy, numpy.finfo(dtype).max gives the maximum for the selected floating-point dtype. These expressions answer different scopes: one is Python’s built-in float limit, and the other depends on the dtype you pass.
Find the maximum finite float with sys.float_info.max
The sys module exposes float_info, a named tuple containing details about the built-in float representation, including its maximum finite value. Select its max attribute when you only need the upper limit; printing the whole tuple includes additional details such as precision and the smallest positive normalized value.
Run this standard-library lookup:
import sys
print(sys.float_info.max)
1.7976931348623157e+308
The expression returns a finite Python float. Its displayed decimal form is 1.7976931348623157e+308. Use this value when you need the upper finite limit of the built-in type, for example when setting a finite sentinel or checking a calculation’s range. It does not describe every numeric type in Python: integers, for instance, do not share this floating-point limit.
Use numpy.finfo() for a floating-point type
For NumPy arrays, ask numpy.finfo() about the dtype you use. Its max attribute is the largest finite value for that dtype. The following example selects numpy.float64; it does not change the limit of Python’s built-in float or report a limit for every NumPy dtype.
Run this example for numpy.float64:
import numpy as np
print(np.finfo(np.float64).max)
1.7976931348623157e+308
Pass another floating-point dtype to inspect its corresponding limits. This is useful when choosing a bound for an array computation or checking which range a dtype supports. The finfo spelling matters: numpy.finfo(dtype) is the function that reports floating-point machine limits. NumPy must be installed in the environment where this example is run; the standard-library approach above does not require it.
Finite maximum versus infinity
The largest finite value and positive infinity are distinct. sys.float_info.max is a finite number. By contrast, float('inf') and math.inf represent positive infinity, a special value greater than any finite float. Use infinity when the computation or algorithm specifically needs an unbounded sentinel; do not use it when you need the largest finite value.
Run this comparison of the finite maximum and positive infinity:
import math
import sys
largest_finite = sys.float_info.max
positive_infinity = float("inf")
print(largest_finite)
print(math.inf == positive_infinity)
print(largest_finite < positive_infinity)
1.7976931348623157e+308
True
True
math.inf is another way to refer to positive infinity, while -math.inf represents negative infinity. Neither is the maximum finite float. Keep the distinction in mind when naming variables or validating results: a check for finiteness and a check against the largest finite value answer different questions. For the built-in limit, use sys.float_info.max; for a NumPy floating-point type, use numpy.finfo(dtype).max with the dtype your data actually uses.