Skip to content
Tcl Source Code Artifact [8908e7a353]
Login

Artifact [8908e7a353]

Artifact 8908e7a353e17ce3d891606e45005d9cc484cf2e:

Ticket change [8908e7a353] - Ticket [221072ffffffffff|221072ffff] <i>rand() &gt; 1 on 64-bit platform</i> status still Open with 4 other changes by dgp on 2000-11-09 02:15:24.
D 2000-11-09T02:15:24
J icomment OK,\shere's\sthe\spatch\sincorporating\sall\sthe\scomments\nand\scorrections\sI've\sseen:\n\nIndex:\sgeneric/tclExecute.c\n===================================================================\nRCS\sfile:\s/home/cvs/cvsroot/sun/tcl/generic/tclExecute.c,v\nretrieving\srevision\s1.1.1.13\nretrieving\srevision\s1.9\ndiff\s-c\s-r1.1.1.13\s-r1.9\n***\stclExecute.c2000/11/06\s16:26:531.1.1.13\n---\stclExecute.c2000/11/06\s19:34:191.9\n***************\n***\s4042,4052\s****\n\s\s\s\s\s\sregister\sint\sstackTop;/*\sCached\stop\sindex\sof\sevaluation\sstack.\s*/\n\s\s\s\s\s\sInterp\s*iPtr\s=\s(Interp\s*)\sinterp;\n\s\s\s\s\s\sdouble\sdResult;\n!\s\s\s\s\sint\stmp;\n\s\s\n\s\s\s\s\s\sif\s(!(iPtr->flags\s&\sRAND_SEED_INITIALIZED))\s{\n\s\siPtr->flags\s|=\sRAND_SEED_INITIALIZED;\n\s\siPtr->randSeed\s=\sTclpGetClicks();\n\s\s\s\s\s\s}\n\s\s\s\s\s\s\n\s\s\s\s\s\s/*\n---\s4042,4062\s----\n\s\s\s\s\s\sregister\sint\sstackTop;/*\sCached\stop\sindex\sof\sevaluation\sstack.\s*/\n\s\s\s\s\s\sInterp\s*iPtr\s=\s(Interp\s*)\sinterp;\n\s\s\s\s\s\sdouble\sdResult;\n!\s\s\s\s\slong\stmp;/*\sAlgorithm\sassumes\sat\sleast\s32\sbits.\n!\s\s*\sOnly\slong\sguarantees\sthat.\s\sSee\sbelow.\s*/\n\s\s\n\s\s\s\s\s\sif\s(!(iPtr->flags\s&\sRAND_SEED_INITIALIZED))\s{\n\s\siPtr->flags\s|=\sRAND_SEED_INITIALIZED;\n\s\siPtr->randSeed\s=\sTclpGetClicks();\n+\s\n+\s/*\n+\s\s*\sMake\ssure\s1\s<=\srandSeed\s<=\s(2^31)\s-\s2.\s\sSee\sbelow.\n+\s\s*/\n+\s\n+\s\s\s\s\s\s\s\s\siPtr->randSeed\s&=\s(unsigned\slong)\s0x7fffffff;\n+\sif\s((iPtr->randSeed\s==\s0)\s||\s(iPtr->randSeed\s==\s0x7fffffff))\s{\n+\s\s\s\s\siPtr->randSeed\s^=\s123459876;\n+\s}\n\s\s\s\s\s\s}\n\s\s\s\s\s\s\n\s\s\s\s\s\s/*\n***************\n***\s4059,4069\s****\n\s\s\s\s\s\s\s*\sGenerate\sthe\srandom\snumber\susing\sthe\slinear\scongruential\n\s\s\s\s\s\s\s*\sgenerator\sdefined\sby\sthe\sfollowing\srecurrence:\n\s\s\s\s\s\s\s*seed\s=\s(\sIA\s*\sseed\s)\smod\sIM\n!\s\s\s\s\s\s*\swhere\sIA\sis\s16807\sand\sIM\sis\s(2^31)\s-\s1.\s\sIn\sorder\sto\savoid\n!\s\s\s\s\s\s*\spotential\sproblems\swith\sinteger\soverflow,\sthe\s\scode\suses\n!\s\s\s\s\s\s*\sadditional\sconstants\sIQ\sand\sIR\ssuch\sthat\n\s\s\s\s\s\s\s*IM\s=\sIA*IQ\s+\sIR\n!\s\s\s\s\s\s*\sFor\sdetails\son\show\sthis\salgorithm\sworks,\srefer\sto\sthe\sfollowing\n\s\s\s\s\s\s\s*\spapers:\s\n\s\s\s\s\s\s\s*\n\s\s\s\s\s\s\s*S.K.\sPark\s&\sK.W.\sMiller,\s"Random\snumber\sgenerators:\sgood\sones\n---\s4069,4088\s----\n\s\s\s\s\s\s\s*\sGenerate\sthe\srandom\snumber\susing\sthe\slinear\scongruential\n\s\s\s\s\s\s\s*\sgenerator\sdefined\sby\sthe\sfollowing\srecurrence:\n\s\s\s\s\s\s\s*seed\s=\s(\sIA\s*\sseed\s)\smod\sIM\n!\s\s\s\s\s\s*\swhere\sIA\sis\s16807\sand\sIM\sis\s(2^31)\s-\s1.\s\sThe\srecurrence\smaps\n!\s\s\s\s\s\s*\sa\sseed\sin\sthe\srange\s[1,\sIM\s-\s1]\sto\sa\snew\sseed\sin\sthat\ssame\srange.\n!\s\s\s\s\s\s*\sThe\srecurrence\smaps\sIM\sto\s0,\sand\smaps\s0\sback\sto\s0,\sso\sthose\stwo\n!\s\s\s\s\s\s*\svalues\smust\snot\sbe\sallowed\sas\sinitial\svalues\sof\sseed.\n!\s\s\s\s\s\s*\n!\s\s\s\s\s\s*\sIn\sorder\sto\savoid\spotential\sproblems\swith\sinteger\soverflow,\sthe\n!\s\s\s\s\s\s*\srecurrence\sis\simplemented\sin\sterms\sof\sadditional\sconstants\n!\s\s\s\s\s\s*\sIQ\sand\sIR\ssuch\sthat\n\s\s\s\s\s\s\s*IM\s=\sIA*IQ\s+\sIR\n!\s\s\s\s\s\s*\sNone\sof\sthe\soperations\sin\sthe\simplementation\soverflows\sa\s32-bit\n!\s\s\s\s\s\s*\ssigned\sinteger,\sand\sthe\sC\stype\slong\sis\sguaranteed\sto\sbe\sat\sleast\n!\s\s\s\s\s\s*\s32\sbits\swide.\n!\s\s\s\s\s\s*\n!\s\s\s\s\s\s*\sFor\smore\sdetails\son\show\sthis\salgorithm\sworks,\srefer\sto\sthe\sfollowing\n\s\s\s\s\s\s\s*\spapers:\s\n\s\s\s\s\s\s\s*\n\s\s\s\s\s\s\s*S.K.\sPark\s&\sK.W.\sMiller,\s"Random\snumber\sgenerators:\sgood\sones\n***************\n***\s4079,4092\s****\n\s\s#define\sRAND_IR2836\n\s\s#define\sRAND_MASK123459876\n\s\s\n-\s\s\s\s\sif\s(iPtr->randSeed\s==\s0)\s{\n-\s/*\n-\s\s*\sDon't\sallow\sa\s0\sseed,\ssince\sit\sbreaks\sthe\sgenerator.\s\sShift\n-\s\s*\sit\sto\ssome\sother\svalue.\n-\s\s*/\n-\s\n-\siPtr->randSeed\s=\s123459876;\n-\s\s\s\s\s}\n\s\s\s\s\s\stmp\s=\siPtr->randSeed/RAND_IQ;\n\s\s\s\s\s\siPtr->randSeed\s=\sRAND_IA*(iPtr->randSeed\s-\stmp*RAND_IQ)\s-\sRAND_IR*tmp;\n\s\s\s\s\s\sif\s(iPtr->randSeed\s<\s0)\s{\n---\s4098,4103\s----\n***************\n***\s4094,4107\s****\n\s\s\s\s\s\s}\n\s\s\n\s\s\s\s\s\s/*\n!\s\s\s\s\s\s*\sOn\s64-bit\sarchitectures\swe\sneed\sto\smask\soff\sthe\supper\sbits\sto\n!\s\s\s\s\s\s*\sensure\swe\sonly\shave\sa\s32-bit\srange.\s\sThe\sconstant\shas\sthe\n!\s\s\s\s\s\s*\sbizarre\sform\sbelow\sin\sorder\sto\smake\ssure\sthat\sit\sdoesn't\n!\s\s\s\s\s\s*\sget\ssign-extended\s(the\srules\sfor\ssign\sextension\sare\svery\n!\s\s\s\s\s\s*\sconcat,\sparticularly\son\s64-bit\smachines).\n\s\s\s\s\s\s\s*/\n\s\s\n-\s\s\s\s\siPtr->randSeed\s&=\s((((unsigned\slong)\s0xfffffff)\s<<\s4)\s|\s0xf);\n\s\s\s\s\s\sdResult\s=\siPtr->randSeed\s*\s(1.0/RAND_IM);\n\s\s\n\s\s\s\s\s\s/*\n---\s4105,4114\s----\n\s\s\s\s\s\s}\n\s\s\n\s\s\s\s\s\s/*\n!\s\s\s\s\s\s*\sSince\sthe\srecurrence\skeeps\sseed\svalues\sin\sthe\srange\s[1,\sRAND_IM\s-\s1],\n!\s\s\s\s\s\s*\sdividing\sby\sRAND_IM\syields\sa\sdouble\sin\sthe\srange\s(0,\s1).\n\s\s\s\s\s\s\s*/\n\s\s\n\s\s\s\s\s\sdResult\s=\siPtr->randSeed\s*\s(1.0/RAND_IM);\n\s\s\n\s\s\s\s\s\s/*\n***************\n***\s4248,4258\s****\n\s\s\s\s\s\s}\n\s\s\s\s\s\s\n\s\s\s\s\s\s/*\n!\s\s\s\s\s\s*\sReset\sthe\sseed.\n\s\s\s\s\s\s\s*/\n\s\s\n\s\s\s\s\s\siPtr->flags\s|=\sRAND_SEED_INITIALIZED;\n\s\s\s\s\s\siPtr->randSeed\s=\si;\n\s\s\n\s\s\s\s\s\s/*\n\s\s\s\s\s\s\s*\sTo\savoid\sduplicating\sthe\srandom\snumber\sgeneration\scode\swe\ssimply\n---\s4255,4270\s----\n\s\s\s\s\s\s}\n\s\s\s\s\s\s\n\s\s\s\s\s\s/*\n!\s\s\s\s\s\s*\sReset\sthe\sseed.\s\sMake\ssure\s1\s<=\srandSeed\s<=\s2^31\s-\s2.\n!\s\s\s\s\s\s*\sSee\scomments\sin\sExprRandFunc()\sfor\smore\sdetails.\n\s\s\s\s\s\s\s*/\n\s\s\n\s\s\s\s\s\siPtr->flags\s|=\sRAND_SEED_INITIALIZED;\n\s\s\s\s\s\siPtr->randSeed\s=\si;\n+\s\s\s\s\siPtr->randSeed\s&=\s(unsigned\slong)\s0x7fffffff;\n+\s\s\s\s\sif\s((iPtr->randSeed\s==\s0)\s||\s(iPtr->randSeed\s==\s0x7fffffff))\s{\n+\siPtr->randSeed\s^=\s123459876;\n+\s\s\s\s\s}\n\s\s\n\s\s\s\s\s\s/*\n\s\s\s\s\s\s\s*\sTo\savoid\sduplicating\sthe\srandom\snumber\sgeneration\scode\swe\ssimply\nIndex:\stests/expr-old.test\n===================================================================\nRCS\sfile:\s/home/cvs/cvsroot/sun/tcl/tests/expr-old.test,v\nretrieving\srevision\s1.1.1.12\nretrieving\srevision\s1.8\ndiff\s-c\s-r1.1.1.12\s-r1.8\n***\sexpr-old.test2000/06/07\s14:41:531.1.1.12\n---\sexpr-old.test2000/11/06\s19:34:191.8\n***************\n***\s825,830\s****\n---\s825,836\s----\n\s\stest\sexpr-old-32.51\s{math\sfunctions\sin\sexpressions}\s{\n\s\s\s\s\s\slist\s[catch\s{expr\s{srand([lindex\s"6ty"\s0])}}\smsg]\s$msg\n\s\s}\s{1\s{argument\sto\smath\sfunction\sdidn't\shave\snumeric\svalue}}\n+\stest\sexpr-old-32.52\s{math\sfunctions\sin\sexpressions}\s{\n+\s\s\s\s\sexpr\s{srand(1<<37)\s<\s1}\n+\s}\s{1}\n+\stest\sexpr-old-32.53\s{math\sfunctions\sin\sexpressions}\s{\n+\s\s\s\s\sexpr\s{srand((1<<31)\s-\s1)\s>\s0}\n+\s}\s{1}\n\s\s\n\s\stest\sexpr-old-33.1\s{conversions\sand\sfancy\sargs\sto\smath\sfunctions}\s{\n\s\s\s\s\s\sexpr\shypot\s(\s3\s,\s4\s)\n\n
J login dgp
J mimetype text/plain
J username dgp
K 221072ffffffffffffffffffffffffffffffffff
U dgp
Z 026396ec2fe5726ab57c0fa226e2dc75