【Python】inf & nan

2023-05-23  本文已影响0人  盐果儿

"inf" stands for "infinity," while "nan" stands for "not a number." These are special floating-point values that can occur in numerical computations.

Infinity (inf): In floating-point arithmetic, "inf" represents positive infinity (+∞) or negative infinity (-∞). It occurs when a value exceeds the maximum finite value that can be represented by the floating-point format. For example, dividing a positive number by zero or performing other operations that result in overflow can lead to an infinite value.

Not a Number (nan): "nan" represents an undefined or indeterminate value. It typically occurs as a result of invalid operations, such as dividing zero by zero or taking the square root of a negative number. "nan" indicates that the result of the operation is not meaningful or cannot be determined.

上一篇下一篇

猜你喜欢

热点阅读