[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
union in oct-rand.cc
From: |
Clinton Chee |
Subject: |
union in oct-rand.cc |
Date: |
Fri, 3 Jun 2005 02:41:41 -0500 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.2) Gecko/20040805 Netscape/7.2 |
Hi All,
RE: Octave-2.9.3,
Some corrections may be needed for liboctave/oct-rand.cc for the 2
functions listed below, in particular the use of union to group one
double with two int or long. There may be several ways to solve this.
double
octave_rand::seed (void)
{
maybe_initialize ();
union d2i { double d; octave_idx_type i[2]; };
union d2i u;
F77_FUNC (getsd, GETSD) (u.i[0], u.i[1]);
return u.d;
}
void
octave_rand::seed (double s)
{
maybe_initialize ();
union d2i { double d; octave_idx_type i[2]; };
union d2i u;
u.d = s;
int i0 = force_to_fit_range (u.i[0], 1, 2147483563);
int i1 = force_to_fit_range (u.i[1], 1, 2147483399);
F77_FUNC (setsd, SETSD) (i0, i1);
}
CORRECTIONS
double
octave_rand::seed (void)
{
maybe_initialize ();
if (sizeof(double) == 2*sizeof(octave_idx_type)) {
union d2i { double d; octave_idx_type i[2]; };
union d2i u;
F77_FUNC (getsd, GETSD) (u.i[0], u.i[1]);
}elseif (sizeof(double) == sizeof(octave_idx_type)){
union d2i { double d; int i[2]; };
union d2i u;
octave_idx_type i0=0;
octave_idx_type i1=0;
F77_FUNC (getsd, GETSD) (i0, i1);
u.i[0] = force_to_fit_range (i0, 1, 2147483563);
u.i[1] = force_to_fit_range (i1, 1, 2147483399);
}else{
printf("Unaccounted case\n");
assert(0);
}
return u.d;
}
void
octave_rand::seed (double s)
{
maybe_initialize ();
union d2i { double d; int i[2]; };
union d2i u;
u.d = s;
octave_idx_type i0 = force_to_fit_range (u.i[0], 1, 2147483563);
octave_idx_type i1 = force_to_fit_range (u.i[1], 1, 2147483399);
F77_FUNC (setsd, SETSD) (i0, i1);
}
Does any of these corrections violate the logic or other implicit
intention of the two original functions?
Cheers,
Clinton
----------------------------------------------------------------------------
Clinton Chee
Computational Scientist
High Performance Computing Unit
Room 2075, Red Centre
University of New South Wales
Australia 2035
chee at parallel stop hpc stop unsw stop edu stop au
Tel: 61 2 9385 6915
----------------------------------------------------------------------------
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- union in oct-rand.cc,
Clinton Chee <=