Skip to content

Commit a84bf7d

Browse files
committed
bring back check for std::rand(), and fix use of result
1 parent 5ba4f3e commit a84bf7d

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

configure

+30-1
Original file line numberDiff line numberDiff line change
@@ -28204,6 +28204,35 @@ printf "%s\n" "#define IPOPT_HAS_RAND 1" >>confdefs.h
2820428204

2820528205
fi
2820628206

28207+
28208+
28209+
28210+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for std::srand" >&5
28211+
printf %s "checking for std::srand... " >&6; }
28212+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
28213+
/* end confdefs.h. */
28214+
#include <cstdlib>
28215+
int main ()
28216+
{ (void) std::srand(1) ;
28217+
return 0 ; }
28218+
28219+
_ACEOF
28220+
if ac_fn_cxx_try_compile "$LINENO"
28221+
then :
28222+
28223+
printf "%s\n" "#define IPOPT_HAS_STD__RAND 1" >>confdefs.h
28224+
28225+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
28226+
printf "%s\n" "yes" >&6; }
28227+
else case e in #(
28228+
e)
28229+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
28230+
printf "%s\n" "no" >&6; } ;;
28231+
esac
28232+
fi
28233+
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
28234+
28235+
2820728236
##################
2820828237
# feenableexcept #
2820928238
##################
@@ -28412,7 +28441,7 @@ else case e in #(
2841228441
JAVA_TEST=Test.java
2841328442
CLASS_TEST=Test.class
2841428443
cat << \EOF > $JAVA_TEST
28415-
/* #line 28415 "configure" */
28444+
/* #line 28444 "configure" */
2841628445
public class Test {
2841728446
}
2841828447
EOF

configure.ac

+4
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,10 @@ AC_CHECK_DECL([drand48],[AC_DEFINE([IPOPT_HAS_DRAND48],[1],
328328
AC_CHECK_DECL([rand],[AC_DEFINE([IPOPT_HAS_RAND],[1],
329329
[Define to 1 if function rand is available])],,[#include <cstdlib>])
330330

331+
AC_COIN_CHECK_NAMESPACE_DECL([std::srand],[1],
332+
[AC_DEFINE([IPOPT_HAS_STD__RAND],[1],[Define to 1 if function std::rand is available])],[],
333+
[#include <cstdlib>])
334+
331335
##################
332336
# feenableexcept #
333337
##################

src/Common/IpUtils.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Number IpRandom01()
113113
# ifdef IPOPT_HAS_RAND
114114
return Number(rand()) / Number(RAND_MAX);
115115
# else
116-
# ifdef HAVE_STD__RAND
116+
# ifdef IPOPT_HAS_STD__RAND
117117
return Number(std::rand()) / Number(RAND_MAX);
118118
# else
119119
# error "don't have function for random number generator"
@@ -130,7 +130,7 @@ void IpResetRandom01()
130130
# ifdef IPOPT_HAS_RAND
131131
srand(1);
132132
# else
133-
# ifdef HAVE_STD__RAND
133+
# ifdef IPOPT_HAS_STD__RAND
134134
std::srand(1);
135135
# else
136136
# error "don't have function for random number generator"

src/Common/config.h.in

+3
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@
132132
/* Define to 1 if the Spral package is available */
133133
#undef IPOPT_HAS_SPRAL
134134

135+
/* Define to 1 if function std::rand is available */
136+
#undef IPOPT_HAS_STD__RAND
137+
135138
/* Define to 1 if va_copy is available */
136139
#undef IPOPT_HAS_VA_COPY
137140

0 commit comments

Comments
 (0)