Home > Archive > Fortran > October 2004 > mtprng or abs() problem; g95
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
mtprng or abs() problem; g95
|
|
| Lucian Anton 2004-10-29, 3:58 pm |
| 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
| |
| James Giles 2004-10-29, 3:58 pm |
| Lucian 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
| |
| glen herrmannsfeldt 2004-10-29, 8:56 pm |
|
Lucian 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
| |
| Scott Robert Ladd 2004-10-29, 8:56 pm |
| On 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
|
|
|
|
|