Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

mtprng or abs() problem; g95
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

Report this thread to moderator Post Follow-up to this message
Old Post
Lucian Anton
10-29-04 08:58 PM


Re: mtprng or abs() problem; g95
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



Report this thread to moderator Post Follow-up to this message
Old Post
James Giles
10-29-04 08:58 PM


Re: mtprng or abs() problem; g95

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


Report this thread to moderator Post Follow-up to this message
Old Post
glen herrmannsfeldt
10-30-04 01:56 AM


Re: mtprng or abs() problem; g95
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 wend.

--
Scott Robert Ladd
site: http://www.coyotegulch.com
blog: http://chaoticcoyote.blogspot.com



Report this thread to moderator Post Follow-up to this message
Old Post
Scott Robert Ladd
10-30-04 01:56 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Fortran archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:26 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.