View previous topic :: View next topic |
Author |
Message |
strsh
Joined: 16 Jul 2013 Posts: 37
|
About the range |
Posted: Wed Jun 24, 2020 1:42 am |
|
|
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
|
|
Posted: Wed Jun 24, 2020 1:59 am |
|
|
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
|
|
Posted: Wed Jun 24, 2020 2:05 am |
|
|
Thanks for your reply. I will accept the proposal.
Thank you. |
|
|
|