CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

About the range

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
strsh



Joined: 16 Jul 2013
Posts: 37

View user's profile Send private message

About the range
PostPosted: Wed Jun 24, 2020 1:42 am     Reply with quote

Regards,
I have one quick question.
How to simplify the code?

Code:
 if (error<=49 && error>=11) .....


The variable error should be in the range of 11 to 49 (11<=error=<49)
Thanks in advance.
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Wed Jun 24, 2020 1:59 am     Reply with quote

I don't think there is any way to 'simplify' this.
At the end of the day, the processor doesn't have a 'range' test in it's
instruction set, so it is going to have to involve two limit tests.
I'd personally have them the other way round, just for readability:

if (error>=11 && error<=49)

since this makes it plainer that you are looking for a number between
11 and 49 inclusive. However has no effect on the code really.
For ultimate 'speed', there can be a tiny improvement, if (for instance)
you know that being below the range is more likely than being above,
by putting the more likely test to fail first. It only does the second
test, when the number has already passed the first.
strsh



Joined: 16 Jul 2013
Posts: 37

View user's profile Send private message

PostPosted: Wed Jun 24, 2020 2:05 am     Reply with quote

Thanks for your reply. I will accept the proposal.
Thank you.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
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