Skip to content

Clarify the return value ​​of the exponentiation methods in special cases #148316

@sorairolake

Description

@sorairolake

Location (URL)

For floating-point types (including f32 etc.):

For integer types (including u8 etc.):

Summary

The following is a table of the return value ​​of the exponentiation methods in special cases:

self n/exp Return value
x ±0 1 for any x
1 y 1 for any y
x 1 x for any x
NAN y NAN
x NAN NAN
±0 y INFINITY or NEG_INFINITY for y an odd integer < 0
±0 NEG_INFINITY INFINITY
±0 INFINITY +0
±0 y INFINITY for finite y < 0 and not an odd integer
±0 y ±0 for y an odd integer > 0
±0 y +0 for finite y > 0 and not an odd integer
-1 INFINITY or NEG_INFINITY 1
x INFINITY INFINITY for |x| > 1
x NEG_INFINITY +0 for |x| > 1
x INFINITY +0 for |x| < 1
x NEG_INFINITY INFINITY for |x| < 1
INFINITY y INFINITY for y > 0
INFINITY y +0 for y < 0
NEG_INFINITY y (-0).pow(-y)
x y NAN for finite x < 0 and finite non-integer y

Some programming language documentation has descriptions similar to this:

I think this can be expressed as doc comments or doctests. This is primarily intended for floating-point types, but I think some of it can be used for integer types as well.

In particular, in most programming languages, zero to the power of zero ($0^0$) returns 1, but in some programming languages it is undefined or ​​it returns an error. So I think it's useful to be clear the return value ​​of the exponentiation methods in special cases.

Metadata

Metadata

Assignees

Labels

A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsT-libsRelevant to the library team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions