Skip to content

Commit

Permalink
bring back check for std::rand(), and fix use of result
Browse files Browse the repository at this point in the history
  • Loading branch information
svigerske committed Dec 13, 2024
1 parent 5ba4f3e commit a84bf7d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
31 changes: 30 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -28204,6 +28204,35 @@ printf "%s\n" "#define IPOPT_HAS_RAND 1" >>confdefs.h

fi




{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for std::srand" >&5
printf %s "checking for std::srand... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <cstdlib>
int main ()
{ (void) std::srand(1) ;
return 0 ; }

_ACEOF
if ac_fn_cxx_try_compile "$LINENO"
then :

printf "%s\n" "#define IPOPT_HAS_STD__RAND 1" >>confdefs.h

{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; }
else case e in #(
e)
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; } ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext


##################
# feenableexcept #
##################
Expand Down Expand Up @@ -28412,7 +28441,7 @@ else case e in #(
JAVA_TEST=Test.java
CLASS_TEST=Test.class
cat << \EOF > $JAVA_TEST
/* #line 28415 "configure" */
/* #line 28444 "configure" */
public class Test {
}
EOF
Expand Down
4 changes: 4 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ AC_CHECK_DECL([drand48],[AC_DEFINE([IPOPT_HAS_DRAND48],[1],
AC_CHECK_DECL([rand],[AC_DEFINE([IPOPT_HAS_RAND],[1],
[Define to 1 if function rand is available])],,[#include <cstdlib>])

AC_COIN_CHECK_NAMESPACE_DECL([std::srand],[1],
[AC_DEFINE([IPOPT_HAS_STD__RAND],[1],[Define to 1 if function std::rand is available])],[],
[#include <cstdlib>])

##################
# feenableexcept #
##################
Expand Down
4 changes: 2 additions & 2 deletions src/Common/IpUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Number IpRandom01()
# ifdef IPOPT_HAS_RAND
return Number(rand()) / Number(RAND_MAX);
# else
# ifdef HAVE_STD__RAND
# ifdef IPOPT_HAS_STD__RAND
return Number(std::rand()) / Number(RAND_MAX);
# else
# error "don't have function for random number generator"
Expand All @@ -130,7 +130,7 @@ void IpResetRandom01()
# ifdef IPOPT_HAS_RAND
srand(1);
# else
# ifdef HAVE_STD__RAND
# ifdef IPOPT_HAS_STD__RAND
std::srand(1);
# else
# error "don't have function for random number generator"
Expand Down
3 changes: 3 additions & 0 deletions src/Common/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@
/* Define to 1 if the Spral package is available */
#undef IPOPT_HAS_SPRAL

/* Define to 1 if function std::rand is available */
#undef IPOPT_HAS_STD__RAND

/* Define to 1 if va_copy is available */
#undef IPOPT_HAS_VA_COPY

Expand Down

0 comments on commit a84bf7d

Please sign in to comment.