maybe
{
double dR,dRM,r;
r = ((double)(SysRandom(0)));
dRM = ((double)(sysRandomMax))
if(dRM == 0)
//Prevent divide by zero
dR = ((r / dRM) - 0.5) * 2.0;
return(dR);
}
at least you will be able to test dRM and make sure it remains valid and is
> 0
also make sure you have all compiler optimizations turned off
----- Original Message -----
From: "Erik Blake" <[EMAIL PROTECTED]>
To: "Palm Developer Forum" <[EMAIL PROTECTED]>
Sent: Friday, May 25, 2001 12:46 PM
Subject: Illegal instruction when multiplying two ints?
> I'm hoping someone can steer me in the right direction here - I'm not
> confident enough to claim I've found a compiler bug, but the behaviour is
> decidedly strange.
>
> Two routine have been variously giving me "Illegal instruction", "Bus
> error", "Line 1111 code error", and "Line 1010 code error" errors in POSE
> (the line code errors to not relate to source code lines, but appear to be
> code page errors). The routines are very innocuous and the frustrating
> thing is that sometimes they work! I'll be fussing away for an hour or so,
> recompiling with various permutations on sequencing the operations, and
> then the problems mysteriously go away. I've tried recompiling all
modules.
>
> These are the routines:
>
> double dRand(void)
>
/***************************************************************************
***
> * This routine returns a random value between -1.0 and +1.0
>
****************************************************************************
*/
> {
> double dR;
> Int16 r;
>
> r = SysRandom(0);
> dR = (((double)r / (double)sysRandomMax) - 0.5) * 2.0;
> return(dR);
> }
>
> (investigation by splitting up the computation reveals that it is the
> double cast of sysRamdomMax that fails (sometimes!).
>
>
> void vDelay(UInt32 uTime)
> // This routine delays for the period of time specified in ms.
> {
> UInt32 uTicks;
> Char s1[20];
>
> uTicks = uTime * gTicksPerSecond;
> uTicks /= 1000;
>
> SysTaskDelay(uTicks);
> }
>
> (here the multiplication fails! If the global variable is copied to a
local
> variable the problem does not go away).
>
> I am using the floating point patch for GCC. These routines are (with many
> others) in a names section (code is more than 64k).
>
> Hope someone has an idea or two....
>
> Erik Blake
> -------------------------------------------------------------------
> Icefield Tools Corporation tel: (867) 633-4264
> 3C Glacier Road fax: (867) 633-4217
> Whitehorse, Yukon CANADA e-mail: [EMAIL PROTECTED]
> Y1A 5S7 internet: http://www.icefieldtools.com/
>
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/tech/support/forums/
>
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/