Commit cdc5524f by Thomas Koenig Committed by Thomas Koenig

re PR libfortran/28452 (__gfortran_random_r10 not found)

2006-08-01  Thomas Koenig  <Thomas.Koenig@online.de>

	PR libfortran/28542
	* Makefile.am:  Remove normalize.c.
	* aclocal.m4:  Regenerate using aclocal 1.9.3.
	* Makefile.in:  Regenerate using automake 1.9.3.
	* libgfortran.h:  #include <float.h>.
	Define GFC_REAL_*_DIGITS and GFC_REAL_*_RADIX.
	Remove prototypes for normalize_r4_i4 and normalize_r8_i8.
	* intrinsics/random.c (top level): Add prototypes for
	random_r10, arandom_r10, random_r16 and arandom_r16.
	(rnumber_4):  New static function.
	(rnumber_8):  New static function.
	(rnumber_10): New static function.
	(rnumber_16): New static function.
	(top level):  Set to kiss_size to 12 if we have
	REAL(KIND=16), to 8 otherwise.
	Define KISS_DEFAULT_SEED_1, KISS_DEFAULT_SEED_2 and
	KISS_DEFAULT_SEED_3.
	(kiss_random_kernel):  Take argument to differentiate
	between different random number generators.
	(random_r4):  Add argument to call to kiss_random_kernel,
	use rnumber_*.
	(random_r8):  Likewise.
	(random_r10):  New function.
	(random_r16):  New function.
	(arandom_r4):  Add argument to call to kiss_random_kernel,
	use_rnumber_*.
	(arandom_r8):  Likewise.
	(arandom_r10):  New function.
	(arandom_r16):  New function.
	* intrinsics/rand.c (rand):  Use shift and mask.
	* runtime/normalize.c:  Remove.

2006-08-01  Thomas Koenig  <Thomas.Koenig@online.de>

	PR libfortran/28542
	* gfortran.dg/random_3.f90:  New test.

From-SVN: r115858
parent a82f93ac
2006-08-01 Thomas Koenig <Thomas.Koenig@online.de>
PR libfortran/28542
* gfortran.dg/random_3.f90: New test.
2006-08-01 Steve Ellcey <sje@cup.hp.com>
PR c++/28432
! { dg-do run }
! { dg-require-effective-target fortran_large_real }
! Check that the random_seed for real(10) or real(16) exists and that
! real(8) and real(10) or real(16) random number generators
! return the same sequence of values.
! Mostly copied from random_2.f90
program random_4
integer,parameter :: k = selected_real_kind (precision (0.0_8) + 1)
integer, dimension(:), allocatable :: seed
real(kind=8), dimension(10) :: r8
real(kind=k), dimension(10) :: r10
real, parameter :: delta = 1.d-10
integer n
call random_seed (size=n)
allocate (seed(n))
call random_seed (get=seed)
! Test both array valued and scalar routines.
call random_number(r8)
call random_number (r8(10))
! Reset the seed and get the real(8) values.
call random_seed (put=seed)
call random_number(r10)
call random_number (r10(10))
if (any ((r8 - r10) .gt. delta)) call abort
end program random_4
2006-08-01 Thomas Koenig <Thomas.Koenig@online.de>
PR libfortran/28542
* Makefile.am: Remove normalize.c.
* aclocal.m4: Regenerate using aclocal 1.9.3.
* Makefile.in: Regenerate using automake 1.9.3.
* libgfortran.h: #include <float.h>.
Define GFC_REAL_*_DIGITS and GFC_REAL_*_RADIX.
Remove prototypes for normalize_r4_i4 and normalize_r8_i8.
* intrinsics/random.c (top level): Add prototypes for
random_r10, arandom_r10, random_r16 and arandom_r16.
(rnumber_4): New static function.
(rnumber_8): New static function.
(rnumber_10): New static function.
(rnumber_16): New static function.
(top level): Set to kiss_size to 12 if we have
REAL(KIND=16), to 8 otherwise.
Define KISS_DEFAULT_SEED_1, KISS_DEFAULT_SEED_2 and
KISS_DEFAULT_SEED_3.
(kiss_random_kernel): Take argument to differentiate
between different random number generators.
(random_r4): Add argument to call to kiss_random_kernel,
use rnumber_*.
(random_r8): Likewise.
(random_r10): New function.
(random_r16): New function.
(arandom_r4): Add argument to call to kiss_random_kernel,
use_rnumber_*.
(arandom_r8): Likewise.
(arandom_r10): New function.
(arandom_r16): New function.
* intrinsics/rand.c (rand): Use shift and mask.
* runtime/normalize.c: Remove.
2006-07-30 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libgfortran/28335
......
......@@ -99,8 +99,7 @@ intrinsics/umask.c \
intrinsics/unlink.c \
intrinsics/unpack_generic.c \
runtime/in_pack_generic.c \
runtime/in_unpack_generic.c \
runtime/normalize.c
runtime/in_unpack_generic.c
gfor_src= \
runtime/compile_options.c \
......
# Makefile.in generated by automake 1.9.6 from Makefile.am.
# Makefile.in generated by automake 1.9.3 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005 Free Software Foundation, Inc.
# 2003, 2004 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
......@@ -14,6 +14,8 @@
@SET_MAKE@
SOURCES = $(libgfortran_la_SOURCES) $(libgfortranbegin_la_SOURCES)
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
......@@ -45,8 +47,7 @@ DIST_COMMON = $(am__configure_deps) $(srcdir)/../config.guess \
$(top_srcdir)/configure ChangeLog
subdir = .
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/../config/lead-dot.m4 \
$(top_srcdir)/../config/stdint.m4 $(top_srcdir)/acinclude.m4 \
am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
$(top_srcdir)/../config/acx.m4 \
$(top_srcdir)/../config/no-executables.m4 \
$(top_srcdir)/../libtool.m4 $(top_srcdir)/configure.ac
......@@ -173,7 +174,7 @@ am__objects_30 = associated.lo abort.lo access.lo args.lo bessel.lo \
selected_int_kind.lo selected_real_kind.lo stat.lo symlnk.lo \
system_clock.lo time.lo transpose_generic.lo tty.lo umask.lo \
unlink.lo unpack_generic.lo in_pack_generic.lo \
in_unpack_generic.lo normalize.lo
in_unpack_generic.lo
am__objects_31 =
am__objects_32 = _abs_c4.lo _abs_c8.lo _abs_c10.lo _abs_c16.lo \
_abs_i4.lo _abs_i8.lo _abs_i16.lo _abs_r4.lo _abs_r8.lo \
......@@ -219,7 +220,7 @@ LTPPFCCOMPILE = $(LIBTOOL) --mode=compile $(FC) $(DEFS) \
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
$(AM_FCFLAGS) $(FCFLAGS)
FCLD = $(FC)
FCLINK = $(LIBTOOL) --mode=link $(FCLD) $(AM_FCFLAGS) $(FCFLAGS) \
FCLINK = $(LIBTOOL) --mode=link $(FCLD) $(AM_FFLAGS) $(FCFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) -o $@
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
......@@ -264,6 +265,7 @@ AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
CC = @CC@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CYGPATH_W = @CYGPATH_W@
......@@ -276,6 +278,7 @@ EXEEXT = @EXEEXT@
FC = @FC@
FCFLAGS = @FCFLAGS@
FPU_HOST_HEADER = @FPU_HOST_HEADER@
GREP = @GREP@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
......@@ -303,12 +306,8 @@ SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
VERSION = @VERSION@
ac_ct_AR = @ac_ct_AR@
ac_ct_AS = @ac_ct_AS@
ac_ct_CC = @ac_ct_CC@
ac_ct_FC = @ac_ct_FC@
ac_ct_RANLIB = @ac_ct_RANLIB@
ac_ct_STRIP = @ac_ct_STRIP@
am__leading_dot = @am__leading_dot@
am__tar = @am__tar@
am__untar = @am__untar@
......@@ -321,6 +320,9 @@ build_os = @build_os@
build_subdir = @build_subdir@
build_vendor = @build_vendor@
datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
enable_shared = @enable_shared@
enable_static = @enable_static@
exec_prefix = @exec_prefix@
......@@ -331,18 +333,22 @@ host_cpu = @host_cpu@
host_os = @host_os@
host_subdir = @host_subdir@
host_vendor = @host_vendor@
htmldir = @htmldir@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
multi_basedir = @multi_basedir@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@
......@@ -443,8 +449,7 @@ intrinsics/umask.c \
intrinsics/unlink.c \
intrinsics/unpack_generic.c \
runtime/in_pack_generic.c \
runtime/in_unpack_generic.c \
runtime/normalize.c
runtime/in_unpack_generic.c
gfor_src = \
runtime/compile_options.c \
......@@ -2377,9 +2382,6 @@ in_pack_generic.lo: runtime/in_pack_generic.c
in_unpack_generic.lo: runtime/in_unpack_generic.c
$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o in_unpack_generic.lo `test -f 'runtime/in_unpack_generic.c' || echo '$(srcdir)/'`runtime/in_unpack_generic.c
normalize.lo: runtime/normalize.c
$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o normalize.lo `test -f 'runtime/normalize.c' || echo '$(srcdir)/'`runtime/normalize.c
.f90.o:
$(FCCOMPILE) -c -o $@ $<
......
......@@ -122,7 +122,15 @@ export_proto_np(PREFIX(rand));
GFC_REAL_4
PREFIX(rand) (GFC_INTEGER_4 *i)
{
return normalize_r4_i4 (irand (i) - 1, GFC_RAND_M1 - 1);
GFC_UINTEGER_4 mask;
#if GFC_REAL_4_RADIX == 2
mask = ~ (GFC_UINTEGER_4) 0u << (32 - GFC_REAL_4_DIGITS + 1);
#elif GFC_REAL_4_RADIX == 16
mask = ~ (GFC_UINTEGER_4) 0u << ((8 - GFC_REAL_4_DIGITS) * 4 + 1);
#else
#error "GFC_REAL_4_RADIX has unknown value"
#endif
return ((GFC_UINTEGER_4) (irand(i) -1) & mask) * (GFC_REAL_4) 0x1.p-31f;
}
#ifndef __GTHREAD_MUTEX_INIT
......
......@@ -33,6 +33,7 @@ Boston, MA 02110-1301, USA. */
#include <math.h>
#include <stddef.h>
#include <float.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846264338327
......@@ -240,6 +241,24 @@ internal_proto(l8_to_l4_offset);
#define GFC_REAL_16_HUGE LDBL_MAX
#endif
#define GFC_REAL_4_DIGITS FLT_MANT_DIG
#define GFC_REAL_8_DIGITS DBL_MANT_DIG
#ifdef HAVE_GFC_REAL_10
#define GFC_REAL_10_DIGITS LDBL_MANT_DIG
#endif
#ifdef HAVE_GFC_REAL_16
#define GFC_REAL_16_DIGITS LDBL_MANT_DIG
#endif
#define GFC_REAL_4_RADIX FLT_RADIX
#define GFC_REAL_8_RADIX FLT_RADIX
#ifdef HAVE_GFC_REAL_10
#define GFC_REAL_10_RADIX FLT_RADIX
#endif
#ifdef HAVE_GFC_REAL_16
#define GFC_REAL_16_RADIX FLT_RADIX
#endif
#ifndef GFC_MAX_DIMENSIONS
#define GFC_MAX_DIMENSIONS 7
#endif
......@@ -639,14 +658,6 @@ extern void random_seed (GFC_INTEGER_4 * size, gfc_array_i4 * put,
gfc_array_i4 * get);
iexport_proto(random_seed);
/* normalize.c */
extern GFC_REAL_4 normalize_r4_i4 (GFC_UINTEGER_4, GFC_UINTEGER_4);
internal_proto(normalize_r4_i4);
extern GFC_REAL_8 normalize_r8_i8 (GFC_UINTEGER_8, GFC_UINTEGER_8);
internal_proto(normalize_r8_i8);
/* size.c */
typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, void) array_t;
......
/* Nelper routines to convert from integer to real.
Copyright 2004, 2005 Free Software Foundation, Inc.
Contributed by Paul Brook.
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran 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 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Ligbfortran 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 libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include <math.h>
#include "libgfortran.h"
/* These routines can be sensitive to excess precision, so should really be
compiled with -ffloat-store. */
/* Return the largest value less than one representable in a REAL*4. */
static inline GFC_REAL_4
almostone_r4 (void)
{
#ifdef HAVE_NEXTAFTERF
return nextafterf (1.0f, 0.0f);
#else
/* The volatile is a hack to prevent excess precision on x86. */
static volatile GFC_REAL_4 val = 0.0f;
GFC_REAL_4 x;
if (val != 0.0f)
return val;
val = 0.9999f;
do
{
x = val;
val = (val + 1.0f) / 2.0f;
}
while (val > x && val < 1.0f);
if (val == 1.0f)
val = x;
return val;
#endif
}
/* Return the largest value less than one representable in a REAL*8. */
static inline GFC_REAL_8
almostone_r8 (void)
{
#ifdef HAVE_NEXTAFTER
return nextafter (1.0, 0.0);
#else
static volatile GFC_REAL_8 val = 0.0;
GFC_REAL_8 x;
if (val != 0.0)
return val;
val = 0.9999;
do
{
x = val;
val = (val + 1.0) / 2.0;
}
while (val > x && val < 1.0);
if (val == 1.0)
val = x;
return val;
#endif
}
/* Convert an unsigned integer in the range [0..x] into a
real the range [0..1). */
GFC_REAL_4
normalize_r4_i4 (GFC_UINTEGER_4 i, GFC_UINTEGER_4 x)
{
GFC_REAL_4 r;
r = (GFC_REAL_4) i / (GFC_REAL_4) x;
if (r == 1.0f)
r = almostone_r4 ();
return r;
}
/* Convert an unsigned integer in the range [0..x] into a
real the range [0..1). */
GFC_REAL_8
normalize_r8_i8 (GFC_UINTEGER_8 i, GFC_UINTEGER_8 x)
{
GFC_REAL_8 r;
r = (GFC_REAL_8) i / (GFC_REAL_8) x;
if (r == 1.0)
r = almostone_r8 ();
return r;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment