Skip to content

Commit

Permalink
cimg_math_parser(): Extend random int generator to 64bits integers.
Browse files Browse the repository at this point in the history
  • Loading branch information
dtschump committed Sep 13, 2024
1 parent ab7c3a6 commit 32ae702
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
27 changes: 14 additions & 13 deletions CImg.h
Original file line number Diff line number Diff line change
Expand Up @@ -28593,11 +28593,12 @@ namespace cimg_library {
return cimg::rand(m,M,&mp.rng);
}

static double _mp_rand_int(_cimg_math_parser& mp, unsigned int delta) {
if (!delta) return 0;
if (delta!=cimg::type<unsigned int>::max()) ++delta;
unsigned int val = 0;
do { val = (unsigned int)std::floor(cimg::rand(delta,&mp.rng)); } while (val>delta);
static double _mp_rand_int(_cimg_math_parser& mp, const double delta) {
if (delta>=cimg::type<cimg_uint64>::max()) return cimg::round(cimg::rand(0,delta,&mp.rng));
const cimg_uint64 _delta = (cimg_uint64)delta;
if (!_delta) return 0;
cimg_uint64 val = 0;
do { val = (cimg_uint64)std::floor(cimg::rand(_delta + 1,&mp.rng)); } while (val>_delta);
return val;
}

Expand All @@ -28607,9 +28608,9 @@ namespace cimg_library {
_M = _mp_arg(3);
if (_m>_M) cimg::swap(_m,_M);
const double
m = cimg::type<int>::cut(std::ceil(_m)),
M = cimg::type<int>::cut(std::floor(_M));
return (double)m + _mp_rand_int(mp,(unsigned int)(M - m));
m = cimg::type<cimg_uint64>::cut(std::ceil(_m)),
M = cimg::type<cimg_uint64>::cut(std::floor(_M));
return (double)m + _mp_rand_int(mp,M - m);
}

static double mp_rand_int_0_1(_cimg_math_parser& mp) {
Expand All @@ -28618,8 +28619,8 @@ namespace cimg_library {

static double mp_rand_int_0_N(_cimg_math_parser& mp) {
const double _M = _mp_arg(2);
const bool sgn = _M>=0;
return (sgn?1.0:-1.0)*_mp_rand_int(mp,cimg::type<unsigned int>::cut(std::floor(sgn?_M:-_M)));
const int sgn = _M>=0?1:-1;
return sgn*_mp_rand_int(mp,_M*sgn);
}

static double mp_rand_int_m1_1(_cimg_math_parser& mp) {
Expand All @@ -28638,9 +28639,9 @@ namespace cimg_library {
_M = _mp_arg(3);
if (_m>_M) cimg::swap(_m,_M);
const int
m = cimg::type<int>::cut(std::ceil(_m)) + (include_min?0:1),
M = cimg::type<int>::cut(std::floor(_M)) - (include_max?0:1);
return (double)m + _mp_rand_int(mp,(unsigned int)(M - m));
m = cimg::type<cimg_uint64>::cut(std::ceil(_m)) + (include_min?0:1),
M = cimg::type<cimg_uint64>::cut(std::floor(_M)) - (include_max?0:1);
return (double)m + _mp_rand_int(mp,M - m);
}

static double mp_ui2f(_cimg_math_parser& mp) {
Expand Down
2 changes: 1 addition & 1 deletion html/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<div class="header">
<a href="index.html"><img alt="Logo" src="img/logo_header.jpg" class="center_image" style="margin-top:1em;"/></a>
<h2 style="padding-bottom: 1em">
Latest stable version: <b><a href="http://cimg.eu/files/CImg_.zip">3.4.2</a></b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Current pre-release: <b><a href="http://cimg.eu/files/CImg_latest.zip">3.4.3</a></b> (2024/09/11)
Latest stable version: <b><a href="http://cimg.eu/files/CImg_.zip">3.4.2</a></b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Current pre-release: <b><a href="http://cimg.eu/files/CImg_latest.zip">3.4.3</a></b> (2024/09/12)
</h2>

<hr/>
Expand Down
2 changes: 1 addition & 1 deletion html/header_doxygen.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<div class="header">
<a href="../index.html"><img alt="Logo" src="../img/logo_header.jpg" class="center_image" style="margin-top:1em;"/></a>
<h2 style="padding-bottom: 1em">
Latest stable version: <b><a href="http://cimg.eu/files/CImg_.zip">3.4.2</a></b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Current pre-release: <b><a href="http://cimg.eu/files/CImg_latest.zip">3.4.3</a></b> (2024/09/11)
Latest stable version: <b><a href="http://cimg.eu/files/CImg_.zip">3.4.2</a></b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Current pre-release: <b><a href="http://cimg.eu/files/CImg_latest.zip">3.4.3</a></b> (2024/09/12)
</h2>

<hr/>
Expand Down

0 comments on commit 32ae702

Please sign in to comment.