Code Comments
Programming Forum and web based access to our favorite programming groups.I tried to obtain a random integer between 1,L using the line ir=mod(abs(mtprng_rand(state)),L)+1 where mtprng_rand(state) is the 32 bit integer random number generator of the mtprng package (available at http://www.coyotegulch.com/products...ed_road/#Item4c) Inspecting a segmentation fault I have found that mtprng_rand(state)) hits the value -2147483648 (-2^{-31}) and abs(-2147483648)= -2147483648 in g95 !! Probable the fault is with mtprng_rand(state) function which shoudn't hit this value, but abs() is not friendly in this situation. I am still baffled. Could an expert help with some comments? Yours, Lucian Anton School of Chemical Engineering Manchester Unversity, UK email antonl22 -> yahoo.com
Post Follow-up to this messageLucian Anton wrote: > I tried to obtain a random integer between 1,L using the line > > ir=mod(abs(mtprng_rand(state)),L)+1 > > where mtprng_rand(state) is the 32 bit integer random number > generator of the mtprng package (available at > http://www.coyotegulch.com/products...ed_road/#Item4c) > > Inspecting a segmentation fault I have found that > mtprng_rand(state)) hits the value -2147483648 (-2^{-31}) and > > abs(-2147483648)= -2147483648 in g95 !! > > Probable the fault is with mtprng_rand(state) function which shoudn't > hit this value, but abs() is not friendly in this situation. I am > still baffled. Could an expert help with some comments? Have you tried: ir = modulo(mtprng_rand(state), L) + 1 -- J. Giles "I conclude that there are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies." -- C. A. R. Hoare
Post Follow-up to this messageLucian Anton wrote: (snip) > abs(-2147483648)= -2147483648 in g95 !! And most likely on any machine with twos complement arithmetic. It may also signal overflow if your system has overflow detection and it is turned on. What value did you want it to return? -- glen
Post Follow-up to this messageOn Fri, 29 Oct 2004 11:43:06 -0700, Lucian Anton wrote:
> Inspecting a segmentation fault I have found that
> mtprng_rand(state)) hits the value -2147483648 (-2^{-31}) and
>
> abs(-2147483648)= -2147483648 in g95 !!
I have a solution, but haven't had a chance to post it yet. I'll see what
I can do about finishing up the code, and posting it this w
end.
--
Scott Robert Ladd
site: http://www.coyotegulch.com
blog: http://chaoticcoyote.blogspot.com
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.