Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testlib does NOT give the same output on different platforms #82

Open
Golovanov399 opened this issue Jan 22, 2019 · 3 comments
Open

testlib does NOT give the same output on different platforms #82

Golovanov399 opened this issue Jan 22, 2019 · 3 comments

Comments

@Golovanov399
Copy link

testlib/testlib.h

Lines 673 to 684 in d2880ce

long next(long n)
{
return (long)next((long long)(n));
}
/* Random value in range [0, n-1]. */
unsigned long next(unsigned long n)
{
if (n >= (unsigned long)(LONG_MAX))
__testlib_fail("random_t::next(unsigned long n): n must be less LONG_MAX");
return (unsigned long)next((unsigned long long)(n));
}

long is a different type on 32-bit and 64-bit platforms (as well as unsigned long). The problem can occur when using rnd.any(...) since it basically calls next(container.size()).

@Golovanov399
Copy link
Author

@MikeMirzayanov bump

@HamzaZagha
Copy link

HamzaZagha commented Aug 18, 2020

Until this is fixed, a workaround is to compile your code for 32bit architecture on both platforms.
For g++ on 64bit systems, this is done using the -m32 flag (you might need to install some libraries though, for me I had to install g++-multilib on linux).

@stgatilov
Copy link
Contributor

stgatilov commented Oct 27, 2020

The best fix would be to add methods nextInt, nextLong, nextDouble, etc, and mark the damn template next as deprecated to discourage its use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants