Macro to Function

Hi friends, I'm facing some difficulties to translate this macro to a function, take a look:

1
2
3
4
5
6
7

#define EXPSIZE 2000
extern double neglibleExp;

#define ApprExpProb(R) ((R) > neglibleExp ? \
	0.0 : exps[(int) ((R) / neglibleExp * EXPSIZE + 0.5)])
// exps is a global vector of doubles 


to

1
2
3
4
5
6
 double ApprExpProb (double R) {
  if (R > neglibleExp) {
     // ?
  }
}


What means that "\" character in the macro?
Can anybody give a hand? Thank you!

\ at the end of line means that line break should be ignored.

So you can do:
1
2
3
4
5
6
7
double ApprExpProb (double R) {
  if (R > neglibleExp) {
    return 0;
  } else {
    return exps[(int) ((R) / neglibleExp * EXPSIZE + 0.5)];
  }
}
or, without eliminating ternary operator
1
2
3
double ApprExpProb (double R) {
  return (R) > neglibleExp ? 0.0 : exps[(int) ((R) / neglibleExp * EXPSIZE + 0.5)];
}
Perfect!
Topic archived. No new replies allowed.