bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

pseudo-random numbers in tests


From: Bruno Haible
Subject: pseudo-random numbers in tests
Date: Sat, 03 Mar 2012 14:23:43 +0100
User-agent: KMail/4.7.4 (Linux/3.1.0-1.2-desktop; KDE/4.7.4; x86_64; ; )

Hi

For the unit tests of <math.h> functions, especially of transcendental
functions, I'll need some kind of pseudo-random numbers. Here I'm adding
a set of 1000 precomputed random numbers.

Why precomputed numbers? Why not use the random() function?
Because it is important that the same tests are executed on all functions.
The random() function returns different numbers on different platforms, and
it would be very confusing if a test succeeded on one platform and not on
others due to a difference in the numbers.

Why not use a portable random number generator, such as drand48(), then?
Because when there is a test failure and I want to analyze it in the
debugger, I need to know the argument number up to the last bit. This
is cumbersome when the number is generated (need to use printf with
extra precision) and much easier if the number is a literal from a source
code file.

I'm adding the declarations to macros.h, because a large number of modules
(more than 30) will use this.


2012-03-03  Bruno Haible  <address@hidden>

        Support for pseudo-random numbers in tests.
        * tests/randomf.c: New file.
        * tests/randomd.c: New file.
        * tests/randoml.c: New file.
        * tests/macros.h (randomf, randomd, randoml): New declarations.

=============================== tests/randomf.c ===============================
/* Some random 'float' numbers used by gnulib tests.
   Copyright (C) 2012 Free Software Foundation, Inc.

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

#include <config.h>

/* Specification.  */
#include "macros.h"

/* Some numbers in the interval [0,1).  */

const float randomf[1000] =
{
  /* Some not so random numbers at the beginning.  */
  0.0f,
  /* Then some numbers generated by GNU clisp.  */
  0.5475547223118679f,
  0.34246776881920316f,
  0.5392890035773527f,
  0.7659977466712314f,
  0.981777728216802f,
  0.5072714919036858f,
  0.013067187372820088f,
  0.5939129809588458f,
  0.8656766279019622f,
...
  0.8413959697701179f
};
=============================== tests/randomd.c ===============================
/* Some random 'double' numbers used by gnulib tests.
   Copyright (C) 2012 Free Software Foundation, Inc.

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

#include <config.h>

/* Specification.  */
#include "macros.h"

/* Some numbers in the interval [0,1).  */

const double randomd[1000] =
{
  /* Some not so random numbers at the beginning.  */
  0.0,
  /* Then some numbers generated by GNU clisp.  */
  0.89255299921822260894833866359,
  0.56160033401164667976788987953,
  0.51743003502243816003616725706,
  0.78419011286685927826225711525,
  0.64400370685467819470063888148,
  0.38151255107934048933308886009,
  0.279822118770531878839000163945,
  0.51983544681375980919751125922,
  0.314601557551148376372971500376,
...
  0.65480905235794807223708347609
};
=============================== tests/randoml.c ===============================
/* Some random 'long double' numbers used by gnulib tests.
   Copyright (C) 2012 Free Software Foundation, Inc.

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

#include <config.h>

/* Specification.  */
#include "macros.h"

/* Some numbers in the interval [0,1).  */

const long double randoml[1000] =
{
  /* Some not so random numbers at the beginning.  */
  0.0L,
  /* Then some numbers generated by GNU clisp.  */
  0.709874756135422554674614242046304686448L,
  0.486497838502717923110029188864352615388L,
  0.474019570990182753146861083750226106848L,
  0.998821069612940336401792152067298257397L,
  0.68230324395444341476284133813649237509L,
  0.0812383212795450007980350531141537177532L,
  0.43131112016001535977175708439191217567L,
  0.1596337172541222285215378906083607753005L,
  0.0447361192177328171952931546845870270203L,
...
  0.85076142804383409765024452942896578158L
};
===============================================================================
--- tests/macros.h.orig Sat Mar  3 13:57:45 2012
+++ tests/macros.h      Sat Mar  3 09:36:38 2012
@@ -66,3 +66,8 @@
 /* STREQ (str1, str2)
    Return true if two strings compare equal.  */
 #define STREQ(a, b) (strcmp (a, b) == 0)
+
+/* Some numbers in the interval [0,1).  */
+extern const float randomf[1000];
+extern const double randomd[1000];
+extern const long double randoml[1000];




reply via email to

[Prev in Thread] Current Thread [Next in Thread]