diff options
author | Ulrich Drepper <drepper@redhat.com> | 2006-12-19 08:18:18 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2006-12-19 08:18:18 +0000 |
commit | 5bcba0ed52c291c1758a8daf24a7ed1680b0330f (patch) | |
tree | b9849ac2cc5f9b4be532e8763710e757afac1eee /stdlib/tst-rand48-2.c | |
parent | 9e1444fc3ddba6efabe467007c1e600f4571687c (diff) | |
download | glibc-5bcba0ed52c291c1758a8daf24a7ed1680b0330f.tar.gz glibc-5bcba0ed52c291c1758a8daf24a7ed1680b0330f.tar.xz glibc-5bcba0ed52c291c1758a8daf24a7ed1680b0330f.zip |
[BZ #3747]
2006-12-18 Jakub Jelinek <jakub@redhat.com> [BZ #3747] * stdlib/jrand48_r.c (__jrand48_r): Make sure result is in the [-231 .. 231) range. * stdlib/tst-rand48.c (main): Fix expected values for 64-bit targets. * stdlib/tst-rand48-2.c: New test. * stdlib/Makefile (tests): Add tst-rand48-2.
Diffstat (limited to 'stdlib/tst-rand48-2.c')
-rw-r--r-- | stdlib/tst-rand48-2.c | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/stdlib/tst-rand48-2.c b/stdlib/tst-rand48-2.c new file mode 100644 index 0000000000..3079b98839 --- /dev/null +++ b/stdlib/tst-rand48-2.c @@ -0,0 +1,113 @@ +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <time.h> + +int +main (void) +{ + time_t t = time (NULL); + int i, ret = 0; + double d; + long int l; + struct drand48_data data; + unsigned short int buf[3]; + + srand48 ((long int) t); + for (i = 0; i < 50; i++) + if ((d = drand48 ()) < 0.0 || d >= 1.0) + { + printf ("drand48 %d %g\n", i, d); + ret = 1; + } + + srand48_r ((long int) t, &data); + for (i = 0; i < 50; i++) + if (drand48_r (&data, &d) != 0 || d < 0.0 || d >= 1.0) + { + printf ("drand48_r %d %g\n", i, d); + ret = 1; + } + + buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e; + for (i = 0; i < 50; i++) + if ((d = erand48 (buf)) < 0.0 || d >= 1.0) + { + printf ("erand48 %d %g\n", i, d); + ret = 1; + } + + buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e; + for (i = 0; i < 50; i++) + if (erand48_r (buf, &data, &d) != 0 || d < 0.0 || d >= 1.0) + { + printf ("erand48_r %d %g\n", i, d); + ret = 1; + } + + srand48 ((long int) t); + for (i = 0; i < 50; i++) + if ((l = lrand48 ()) < 0 || l > INT32_MAX) + { + printf ("lrand48 %d %ld\n", i, l); + ret = 1; + } + + srand48_r ((long int) t, &data); + for (i = 0; i < 50; i++) + if (lrand48_r (&data, &l) != 0 || l < 0 || l > INT32_MAX) + { + printf ("lrand48_r %d %ld\n", i, l); + ret = 1; + } + + buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e; + for (i = 0; i < 50; i++) + if ((l = nrand48 (buf)) < 0 || l > INT32_MAX) + { + printf ("nrand48 %d %ld\n", i, l); + ret = 1; + } + + buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e; + for (i = 0; i < 50; i++) + if (nrand48_r (buf, &data, &l) != 0 || l < 0 || l > INT32_MAX) + { + printf ("nrand48_r %d %ld\n", i, l); + ret = 1; + } + + srand48 ((long int) t); + for (i = 0; i < 50; i++) + if ((l = mrand48 ()) < INT32_MIN || l > INT32_MAX) + { + printf ("mrand48 %d %ld\n", i, l); + ret = 1; + } + + srand48_r ((long int) t, &data); + for (i = 0; i < 50; i++) + if (mrand48_r (&data, &l) != 0 || l < INT32_MIN || l > INT32_MAX) + { + printf ("mrand48_r %d %ld\n", i, l); + ret = 1; + } + + buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e; + for (i = 0; i < 50; i++) + if ((l = jrand48 (buf)) < INT32_MIN || l > INT32_MAX) + { + printf ("jrand48 %d %ld\n", i, l); + ret = 1; + } + + buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e; + for (i = 0; i < 50; i++) + if (jrand48_r (buf, &data, &l) != 0 || l < INT32_MIN || l > INT32_MAX) + { + printf ("jrand48_r %d %ld\n", i, l); + ret = 1; + } + + return ret; +} |