Skip to content

Commit

Permalink
[giac] random: randmax2+1.0 fixes
Browse files Browse the repository at this point in the history
move fgamma definition from first.h to usual.cc, insures that config.h defines are defined

git-svn-id: https://dev.geogebra.org/svn/trunk/geogebra/giac@70150 23ce0884-8a58-47d3-bc5c-ddf1cd5b9f9e
  • Loading branch information
bernard.parisse committed Aug 22, 2023
1 parent 30b0fdb commit 618a5de
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/giac/cpp/prog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4020,7 +4020,7 @@ namespace giac {
for (int i=0;i<n-1;++i){
// j ← random integer such that i ≤ j < n
// exchange a[i] and a[j]
int j=int(i+(giac_rand(contextptr)/double(rand_max2))*(n-i));
int j=int(i+(giac_rand(contextptr)/double(rand_max2+1.0))*(n-i));
std::swap(temp[i],temp[j]);
}
}
Expand All @@ -4034,7 +4034,7 @@ namespace giac {
for (int essai=20;essai>=0;--essai){
int i;
for (i=0;i<k;++i)
ts[i]=t[i]=int(giac_rand(contextptr)/double(rand_max2)*n);
ts[i]=t[i]=int(giac_rand(contextptr)/double(rand_max2+1.0)*n);
sort(ts.begin(),ts.end());
for (i=1;i<k;++i){
if (ts[i]==ts[i-1])
Expand All @@ -4048,7 +4048,7 @@ namespace giac {
vector<int> t; t.reserve(k);
// (algorithm suggested by O. Garet)
while (n>0){
int r=int(giac_rand(contextptr)/double(rand_max2)*n);
int r=int(giac_rand(contextptr)/double(rand_max2+1.0)*n);
if (r<n-k) // (n-k)/n=proba that the current n is not in the list
--n;
else {
Expand All @@ -4068,7 +4068,7 @@ namespace giac {
for (int j=0;j<k;++j){
int r=-1;
for (;;){
r=int(giac_rand(contextptr)/double(rand_max2)*n);
r=int(giac_rand(contextptr)/double(rand_max2+1.0)*n);
if (tab[r]){ tab[r]=false; break; }
}
v[j]=r;
Expand Down
10 changes: 10 additions & 0 deletions src/giac/cpp/usual.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ using namespace std;
#define sprintf256 sprintf
#endif

#if defined HAVE_TGAMMAF || defined __APPLE__ || defined EMCC || defined EMCC2 || defined NO_BSD
inline float fgamma(float f1){ return tgammaf(f1); }
#else
#if defined(__MINGW_H) || defined(VISUALC) || defined(FXCG)// FIXME gamma, not used
inline float fgamma(float f1){ return f1; }
#else
inline float fgamma(float f1){ return gammaf(f1); } // or tgammaf(f1) on some versions of emscripten
#endif
#endif

#ifndef NO_NAMESPACE_GIAC
namespace giac {
#endif // ndef NO_NAMESPACE_GIAC
Expand Down
9 changes: 0 additions & 9 deletions src/giac/headers/first.h
Original file line number Diff line number Diff line change
Expand Up @@ -578,15 +578,6 @@ inline float ffloor(float f1){
#endif
}
inline float finv(float f1){ return 1/f1; }
#if defined HAVE_TGAMMAF || defined __APPLE__ || defined EMCC || defined EMCC2 || defined NO_BSD
inline float fgamma(float f1){ return tgammaf(f1); }
#else
#if defined(__MINGW_H) || defined(VISUALC) || defined(FXCG)// FIXME gamma, not used
inline float fgamma(float f1){ return f1; }
#else
inline float fgamma(float f1){ return gammaf(f1); } // or tgammaf(f1) on some versions of emscripten
#endif
#endif
#ifdef FXCG
inline float atan2f(float f1,float f2,int rad){ if (rad) return std::atan2(f1,f2); else return std::atan2(f1,f2)*180/3.14159265358979323846;}
#else
Expand Down

0 comments on commit 618a5de

Please sign in to comment.