8000 ENH: Add a float_power function with at least float64 precision. by charris · Pull Request #8190 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: Add a float_power function with at least float64 precision. #8190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 5, 2016

Conversation

charris
Copy link
Member
@charris charris commented Oct 21, 2016

The new float_power function converts integers and inexact types to inexact types of minimum precision float64 before computing the power. The intent is one should not need to worry about overflow or negative powers when computing a power when type preservation is not a factor. It also follows the suggestion in the mailing list discussion that the return type of the ** operator be double precision.

@charris
Copy link
Member Author
charris commented Oct 21, 2016

This is a work in progress, do not merge yet.

@NeilGirdhar
Copy link
Contributor

Why not have the user convert their array to float32 first?

@charris
Copy link
Member Author
charris commented Oct 22, 2016

@NeilGirdhar Avoiding explicit conversion is the whole point. This arises from the discussion on the mailing list of how the ** operator should behave with integers to (negative) integer powers.

@NeilGirdhar
Copy link
Contributor
NeilGirdhar commented Oct 22, 2016

so fpower(x, y) is basically:

def fpower(x, y):
     if np.issubdtype(x.dtype, np.integer):
         x = x.astype(np.float)
     return np.power(x, y)

?

The new float_power function converts integers and inexact type to
inexact types of minimum precision float64 before computing the power.
The intent is one should not need to worry about overflow or negative
powers when computing a power when type preservation is not a factor. It
also implements the popular proposal on the numpy mailing list that the
`**` operator should always return at least double precision.
@charris
Copy link
Member Author
charris commented Nov 3, 2016

Updated and function renamed float_power.

@NeilGirdhar It is a ufunc, so the output type depends on the type of both inputs. In this case, the minimum precision is float64 as no lesser precision is available for the ufunc to convert to.

@charris charris changed the title ENH: Add an fpower function that converts ints to floats. ENH: Add a float_power function with at least float64 precision. Nov 3, 2016
@charris charris merged commit 62046aa into numpy:master Nov 5, 2016
@charris charris deleted the add-fpower-ufunc branch November 5, 2016 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0