Skip to content

MAINT: Separate correct longdouble.__float__ from incorrect longdouble.__int__ #9967

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 1 commit into from
Nov 6, 2017

Conversation

eric-wieser
Copy link
Member

@eric-wieser eric-wieser commented Nov 5, 2017

These barely shared any useful code at all, and it makes it clearer where the fix needs to go for #9964


dval = (double)(((Py@CHAR@LongDoubleScalarObject *)self)->obval)@POST@;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using PyArrayScalar_VAL in favor of this

* #POST = ,,.real*2#
* #char = ,c#
* #CHAR = ,C#
* #POST = ,.real#
*/
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This repeat is way clearer expressed as two repeats

* Could fix this with a PyLong_FromLongDouble(longdouble ldval)
* but this would need some more work...
*/
return PyLong_FromDouble((double) val);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where things need to change to fix #9964, but lets leave that to a future PR.

*/
@char@longdoubletype_as_number.nb_float = @char@longdoubletype_float;
#if defined(NPY_PY3K)
@char@longdoubletype_as_number.nb_int = @char@longdoubletype_long;
Copy link
Member Author

@eric-wieser eric-wieser Nov 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is deliberate, as nb_int should try to return int on py2, but long on py3. I'm not sure it makes a difference externaly (I suspect python deals with either return value), but it's more consistent with how longobject is implemented.

PyCLongDoubleArrType_Type.@kind@_@name@ = clongdoubletype_@name@;
Py@CHAR@LongDoubleArrType_Type.tp_as_number = &@char@longdoubletype_as_number;
Py@CHAR@LongDoubleArrType_Type.tp_repr = @char@longdoubletype_repr;
Py@CHAR@LongDoubleArrType_Type.tp_str = @char@longdoubletype_str;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's far more readable and concise to iterate over the types here, rather than the members.

…uble.__int__`

These barely shared any useful code at all.
@eric-wieser eric-wieser force-pushed the separate-longdouble-int branch from 49c624a to 7b4ec2a Compare November 5, 2017 23:26
@charris charris merged commit ece0c5d into numpy:master Nov 6, 2017
@charris
Copy link
Member

charris commented Nov 6, 2017

Thanks Eric.

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