Python Glossary Русский

Python 3.15+mathfunction

math.fmin()

comparison

The smaller of two floats, with NaN treated as missing: fmin(nan, 1.0) gives 1.0. The counterpart of math.fmax.

Syntax

math.fmin(x, y)

min() with NaN depends on argument order because comparisons with NaN are always false; fmin returns a number if at least one argument is a number, and NaN only when both are NaN. Handy when aggregating measurements with gaps: functools.reduce(math.fmin, values) is not “infected” by a single NaN. The sign of zero in fmin(0.0, -0.0) is not guaranteed.

Examples

import math, functools
values = [float('nan'), 3.5, 1.25, 2.0]
print(functools.reduce(math.fmin, values))  # → 1.25
print(min(values))  # → nan — NaN первым, и все сравнения с ним ложны

See also

Open in the full glossarydocs.python.orgReport an inaccuracy