forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

If statement for multiples of an integer

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Plato
View previous topic :: View next topic  
Author Message
Kalashnikov



Joined: 25 May 2006
Posts: 7

PostPosted: Tue Apr 10, 2007 12:08 pm    Post subject: If statement for multiples of an integer Reply with quote

Hi

I was hoping someone could offer some advice with the following problem.

I have a loop which executes 8000 times and each time it does, it performs a necessary calculation. However I would like it to print something during the first execution and then at intervals of 32 executions thereafter. In other words, it must print when i=1, 33, 65, 97 etc. The obvious way to do this would be to include an if statement, instructing it to print in the event of "i" in the DO loop being equal to the specified numbers.

This seems very clumsy so I thought it would be better to instruct it to print at i=1 and every time i-1 is a multiple of 32. -Something like the following:

if (i==1 .OR. REAL(i-1)/REAL(32) = [an integer] )

While the above is clearly incorrect, is there a way of going about the problem in this fashion or a similarly economical one?

Thanks in advance,

Mikhail
_________________
Mikhail Kalashnikov
Back to top
View user's profile Send private message
brucebowler
Guest





PostPosted: Tue Apr 10, 2007 2:35 pm    Post subject: Reply with quote

temp = real(i-1)/32.0
if (i == 1 .or. int(temp) == temp)

Subject of course to the ability to represent certain reals "precisely"... It would work better if you could do

temp = real(i)/32.0
if (i == 1 .or. int(temp) == temp)

ie 1,32,64,96, etc...
Back to top
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Tue Apr 10, 2007 3:33 pm    Post subject: Reply with quote

For integer i, the condition you want is

if(MOD(i,32)==1) print ....
Back to top
View user's profile Send private message AIM Address
Kalashnikov



Joined: 25 May 2006
Posts: 7

PostPosted: Tue Apr 10, 2007 4:28 pm    Post subject: Reply with quote

Thank you both very much.
_________________
Mikhail Kalashnikov
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Plato All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group