Click here to Skip to main content
15,906,341 members
Home / Discussions / Algorithms
   

Algorithms

 
AnswerRe: Can comparisons be done without If statements in C Pin
Luc Pattyn11-Dec-06 3:19
sitebuilderLuc Pattyn11-Dec-06 3:19 
GeneralRe: Can comparisons be done without If statements in C Pin
Stephen Hewitt11-Dec-06 15:54
Stephen Hewitt11-Dec-06 15:54 
GeneralRe: Can comparisons be done without If statements in C Pin
Luc Pattyn12-Dec-06 4:27
sitebuilderLuc Pattyn12-Dec-06 4:27 
AnswerRe: Can comparisons be done without If statements in C Pin
Guffa11-Dec-06 4:18
Guffa11-Dec-06 4:18 
AnswerRe: Can comparisons be done without If statements in C Pin
Maximilien11-Dec-06 4:49
Maximilien11-Dec-06 4:49 
AnswerRe: Can comparisons be done without If statements in C Pin
Stephen Hewitt11-Dec-06 15:56
Stephen Hewitt11-Dec-06 15:56 
AnswerRe: Can comparisons be done without If statements in C Pin
ShermansLagoon8-Jan-07 3:09
ShermansLagoon8-Jan-07 3:09 
AnswerRe: Can comparisons be done without If statements in C Pin
Rilhas30-Jan-07 12:57
Rilhas30-Jan-07 12:57 
Try this:

#define MISTERY(x,v) (((x)<(v))? 1 : 0 )
#define SECRET(x,a,b) ( ! ( MISTERY(x,a) || MISTERY(-x,-b) ) )

Then, in your function:

return SECRET(x,0.5,1.0)

Not only I avoided using the dreaded if statement, but I also succeeded in making the code more dificult to predict. A genuine 2 in 1.

Anyway, the only reason I see to avoid using the if statement is to look good when answering a teacher's question! :-P

Rogério Rilhas

PS: I sincerely hope there is no hidden bug in this code!!
Questionhow to read outlook express file inbox.dbx to simple english Pin
naveen padiyar10-Dec-06 19:06
naveen padiyar10-Dec-06 19:06 
QuestionRe: Control generation of my own public & private key pairs using C# Pin
edchan10-Dec-06 18:53
edchan10-Dec-06 18:53 
Questionconvert Metric to English and English to Metric using pseudocod Pin
xcom20018-Dec-06 21:15
xcom20018-Dec-06 21:15 
AnswerRe: convert Metric to English and English to Metric using pseudocod Pin
El Corazon9-Dec-06 6:15
El Corazon9-Dec-06 6:15 
AnswerRe: convert Metric to English and English to Metric using pseudocod Pin
#1239-Dec-06 21:53
#1239-Dec-06 21:53 
GeneralRe: convert Metric to English and English to Metric using pseudocod Pin
toxcct10-Dec-06 4:57
toxcct10-Dec-06 4:57 
GeneralRe: convert Metric to English and English to Metric using pseudocod Pin
Chris Maunder10-Dec-06 9:46
cofounderChris Maunder10-Dec-06 9:46 
GeneralRe: convert Metric to English and English to Metric using pseudocod Pin
#12310-Dec-06 10:34
#12310-Dec-06 10:34 
GeneralRe: convert Metric to English and English to Metric using pseudocod Pin
Chris Maunder10-Dec-06 10:50
cofounderChris Maunder10-Dec-06 10:50 
GeneralRe: convert Metric to English and English to Metric using pseudocod Pin
#12310-Dec-06 12:11
#12310-Dec-06 12:11 
GeneralRe: convert Metric to English and English to Metric using pseudocod Pin
toxcct10-Dec-06 22:30
toxcct10-Dec-06 22:30 
GeneralRe: convert Metric to English and English to Metric using pseudocod Pin
Paul Conrad11-Dec-06 4:23
professionalPaul Conrad11-Dec-06 4:23 
GeneralRe: convert Metric to English and English to Metric using pseudocod Pin
Paul Conrad10-Dec-06 15:40
professionalPaul Conrad10-Dec-06 15:40 
GeneralRe: convert Metric to English and English to Metric using pseudocod Pin
Stephen Hewitt10-Dec-06 14:37
Stephen Hewitt10-Dec-06 14:37 
GeneralRe: convert Metric to English and English to Metric using pseudocod Pin
#12310-Dec-06 15:09
#12310-Dec-06 15:09 
GeneralRe: convert Metric to English and English to Metric using pseudocod Pin
Paul Conrad10-Dec-06 15:45
professionalPaul Conrad10-Dec-06 15:45 
GeneralRe: convert Metric to English and English to Metric using pseudocod Pin
Shog911-Dec-06 13:54
sitebuilderShog911-Dec-06 13:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.