Repository: numpy/numpy

Issue:
Patch for unraised exceptions in cygwin64
On cygwin64, some floating point exceptions are not raised correctly:

``` python
>>> import numpy as np
>>> 1/np.float64(0.0)
inf
```

The reason is that a specific `fenv.h` provided by numpy (probably for cygwin32)  is used in `ieee754.c.src`, instead of the system-wide version. I guess this dates back to times when there was no `fenv.h` on cygwin, but it is now available on both cygwin32 and cygwin64.

A simple patch follows, enabling the system-wide `fenv.h` in `ieee754.c.src` and removing the references to the local `fenv.h` and `fenv.c` in `numpy/core/setup.py`. I don't know if these files can still be useful on some exotic systems or if they can be deleted. With the patch, the correct exception or warning is raised, and almost all tests pass on cygwin64.

```
diff --git a/numpy/core/setup.py b/numpy/core/setup.py
index 75d64d8..7f06491 100644
--- a/numpy/core/setup.py
+++ b/numpy/core/setup.py
@@ -630,15 +630,9 @@ def configuration(parent_package='',top_path=None):

     deps = [join('src', 'npymath', '_signbit.c'),
             join('include', 'numpy', '*object.h'),
-            'include/numpy/fenv/fenv.c',
-            'include/numpy/fenv/fenv.h',
             join(codegen_dir, 'genapi.py'),
             ]

-    # Don't install fenv unless we need them.
-    if sys.platform == 'cygwin':
-        config.add_data_dir('include/numpy/fenv')
-
     #######################################################################
     #                            dummy module                             #
     #######################################################################
diff --git a/numpy/core/src/npymath/ieee754.c.src b/numpy/core/src/npymath/ieee754.c.src
index b8f6889..19ce6bc 100644
--- a/numpy/core/src/npymath/ieee754.c.src
+++ b/numpy/core/src/npymath/ieee754.c.src
@@ -615,13 +615,8 @@ void npy_set_floatstatus_invalid(void)
 #elif defined(__GLIBC__) || defined(__APPLE__) || \
       defined(__CYGWIN__) || defined(__MINGW32__) || \
       (defined(__FreeBSD__) && (__FreeBSD_version >= 502114))
-
-# if defined(__GLIBC__) || defined(__APPLE__) || \
-     defined(__MINGW32__) || defined(__FreeBSD__)
 #  include <fenv.h>
-# elif defined(__CYGWIN__)
-#  include "numpy/fenv/fenv.h"
-# endif
+

 int npy_get_floatstatus(void)
 {
```

BLD: Use system-wide fenv.h on cygwin
Patch as for bug-report #5532. copy-pasting the beginning of the bug report:

On cygwin64, some floating point exceptions are not raised correctly:

``` python
>>> import numpy as np
>>> 1/np.float64(0.0)
inf
```

The reason is that a specific fenv.h provided by numpy (probably for cygwin32) is used in ieee754.c.src, instead of the system-wide version. I guess this dates back to times when there was no fenv.h on cygwin, but it is now available on both cygwin32 and cygwin64.

The PR enables the system-wide fenv.h in ieee754.c.src on cygwin, removes the references to the local fenv.h and fenv.c in numpy/core/setup.py, and deletes these files. With the patch, the correct exception or warning is raised, and almost all tests pass on cygwin64.



Discussion:
@sgouezel thanks for the patch. Would you like to submit this as a PR?

If the files aren't being used, then they should be deleted. If we decide
we want to use them again in the future then we can always find them in the
git history.

On Mon, Feb 2, 2015 at 1:37 PM, sgouezel notifications@github.com wrote:

> On cygwin64, some floating point exceptions are not raised correctly:
> 
> > > > import numpy as np>>> 1/np.float64(0.0)
> > > > inf
> 
> The reason is that a specific fenv.h provided by numpy (probably for
> cygwin32) is used in ieee754.c.src, instead of the system-wide version. I
> guess this dates back to times when there was no fenv.h on cygwin, but it
> is now available on both cygwin32 and cygwin64.
> 
> A simple patch follows, enabling the system-wide fenv.h in ieee754.c.src
> and removing the references to the local fenv.h and fenv.c in
> numpy/core/setup.py. I don't know if these files can still be useful on
> some exotic systems or if they can be deleted. With the patch, the correct
> exception or warning is raised, and almost all tests pass on cygwin64.
> 
> diff --git a/numpy/core/setup.py b/numpy/core/setup.py
> index 75d64d8..7f06491 100644
> --- a/numpy/core/setup.py
> +++ b/numpy/core/setup.py
> @@ -630,15 +630,9 @@ def configuration(parent_package='',top_path=None):
> 
> ```
>  deps = [join('src', 'npymath', '_signbit.c'),
>          join('include', 'numpy', '*object.h'),
> ```
> -            'include/numpy/fenv/fenv.c',
> - ```
>          'include/numpy/fenv/fenv.h',
>        join(codegen_dir, 'genapi.py'),
>        ]
>   ```
> -    # Don't install fenv unless we need them.
> -    if sys.platform == 'cygwin':
> 
> ## \-        config.add_data_dir('include/numpy/fenv')
> 
> ```
>  #######################################################################
>  #                            dummy module                             #
>  #######################################################################
> ```
> 
> diff --git a/numpy/core/src/npymath/ieee754.c.src b/numpy/core/src/npymath/ieee754.c.src
> index b8f6889..19ce6bc 100644
> --- a/numpy/core/src/npymath/ieee754.c.src
> +++ b/numpy/core/src/npymath/ieee754.c.src
> @@ -615,13 +615,8 @@ void npy_set_floatstatus_invalid(void)
>  #elif defined(**GLIBC**) || defined(**APPLE**) || \
>        defined(**CYGWIN**) || defined(**MINGW32**) || \
> 
> ##        (defined(**FreeBSD**) && (__FreeBSD_version >= 502114))
> 
> -# if defined(**GLIBC**) || defined(**APPLE**) || \
> - ```
>   defined(__MINGW32__) || defined(__FreeBSD__)
>   ```
>   
>   # include <fenv.h>
>   
>   -# elif defined(**CYGWIN**)
>   -#  include "numpy/fenv/fenv.h"
>   -# endif
>   +
>   
>   int npy_get_floatstatus(void)
>   {
> 
> —
> Reply to this email directly or view it on GitHub
> https://github.com/numpy/numpy/issues/5532.

## 

Nathaniel J. Smith -- http://vorpus.org



Resolving patch:
diff --git a/numpy/core/setup.py b/numpy/core/setup.py
--- a/numpy/core/setup.py
+++ b/numpy/core/setup.py
@@ -630,15 +630,9 @@ def generate_api(ext, build_dir):
 
     deps = [join('src', 'npymath', '_signbit.c'),
             join('include', 'numpy', '*object.h'),
-            'include/numpy/fenv/fenv.c',
-            'include/numpy/fenv/fenv.h',
             join(codegen_dir, 'genapi.py'),
             ]
 
-    # Don't install fenv unless we need them.
-    if sys.platform == 'cygwin':
-        config.add_data_dir('include/numpy/fenv')
-
     #######################################################################
     #                            dummy module                             #
     #######################################################################


Test patch: