Skip to content

Inconsistency: NaN ** 0.0 = 1.0, but NaN * 0.0 = NaN #133274

Closed as not planned
Closed as not planned
@BikeCrusader

Description

@BikeCrusader

Bug report

Bug description:

x = float("NaN")
# Prints "1.0"
print(x**0.0)
# Prints "nan"
print(x*0.0)
# Prints "nan"
print(x/float("inf"))
# Prints "nan"
print(x+float("inf"))
# Prints "nan"
print(x-float("inf"))

As you can see, the behavior of ** is inconsistent with that of * and +. ** treats NaN like a normal number,
so NaN ** 0.0 = 1.0. But other operations like * and + treat NaN like a special value, since it is not a number.
Therefore, the result of operations like NaN * 0.0 are NaN.
"""

CPython versions tested on:

3.13, 3.11

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions