Skip to content
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

BLD: Fix npy_isnan of integer variables in cephes #8085

Merged
merged 1 commit into from
Oct 26, 2017
Merged

BLD: Fix npy_isnan of integer variables in cephes #8085

merged 1 commit into from
Oct 26, 2017

Conversation

fweimer
Copy link

@fweimer fweimer commented Oct 26, 2017

Commit ede5590 (BUG: special: fix
ufunc results for nan arguments) started to apply npy_isnan to integer
arguments by mistake. GCC's __builtin_isnan issues errors when
applied to integers, so depending on which implementation is chosen by
numpy, this can result in build errors.

Commit ede5590 (BUG: special: fix
ufunc results for nan arguments) started to apply npy_isnan to integer
arguments by mistake.  GCC's __builtin_isnan issues errors when
applied to integers, so depending on which implementation is chosen by
numpy, this can result in build errors.
@pv
Copy link
Member

pv commented Oct 26, 2017 via email

@person142 person142 added this to the 1.1.0 milestone Oct 26, 2017
@person142 person142 merged commit 48f197b into scipy:master Oct 26, 2017
@person142
Copy link
Member

My bad, thanks for the fix @fweimer.

@person142
Copy link
Member

This means we should add a nan check to _legacy_cast_check:

https://github.com/scipy/scipy/blob/master/scipy/special/_legacy.pxd#L40

Otherwise if you pass in a nan it gets cast to an int, which could then in theory give you some garbage non-nan result.

@pv
Copy link
Member

pv commented Oct 26, 2017 via email

@pv
Copy link
Member

pv commented Oct 26, 2017 via email

@person142
Copy link
Member

person142 commented Oct 26, 2017

Of course, if it's undefined behavior, the compiler may choose to emit code running "rm -rf /".

Thankfully on my box I don't get anything that drastic, but the cast to int gives you -2147483648. Now combining that with

>>> sc.bdtrc(-2147483648, 1, 0.0)
1.0

makes one sad. :-(

So on master:

>>> import scipy.special as sc
>>> import numpy as np
>>> sc.bdtrc(np.nan, 1, 0.5)
__main__:1: RuntimeWarning: floating point number truncated to an integer
1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants