Skip to content

Commit

Permalink
BUG: optimize/trlib: patch up for missing fmin&copysign on MSVC9
Browse files Browse the repository at this point in the history
  • Loading branch information
pv committed Aug 22, 2017
1 parent 30348b1 commit e4f1db0
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
53 changes: 53 additions & 0 deletions scipy/optimize/_trlib/trlib/fmax.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@ static int signbit(double x)
return x > 0;
}

static double copysign(double x, double y)
{
if (x >= 0) {
if (y >= 0) {
return x;
}
else {
return -x;
}
}
else {
if (y >= 0) {
return -x;
}
else {
return x;
}
}
}

static double fmax(double x, double y)
{
/* z > nan for z != nan is required by C the standard */
Expand Down Expand Up @@ -42,4 +62,37 @@ static double fmax(double x, double y)
return y;
}
}

static double fmin(double x, double y)
{
/* z > nan for z != nan is required by C the standard */
int xnan = isnan(x), ynan = isnan(y);

if (xnan || ynan)
{
if (xnan && !ynan)
return y;
if (!xnan && ynan)
return x;
return x;
}

/* +0 > -0 is preferred by C the standard */
if (x == 0 && y == 0)
{
int xs = signbit(x), ys = signbit(y);
if (xs && !ys)
return x;
if (!xs && ys)
return y;
return y;
}

if (x > y) {
return y;
}
else {
return x;
}
}
#endif
2 changes: 2 additions & 0 deletions scipy/optimize/_trlib/trlib_quadratic_zero.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "trlib.h"
#include "trlib_private.h"

#include "fmax.h"

trlib_int_t trlib_quadratic_zero(trlib_flt_t c_abs, trlib_flt_t c_lin, trlib_flt_t tol,
trlib_int_t verbose, trlib_int_t unicode, char *prefix, FILE *fout,
trlib_flt_t *t1, trlib_flt_t *t2) {
Expand Down

0 comments on commit e4f1db0

Please sign in to comment.