473,503 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

what mean this " return x < 0 ? 2 - y : y;" in the end of function

1 New Member
Hi
please help me to depict what does mean this " return x < 0 ? 2 - y : y;" in the end of function.

the function is as follows:

Expand|Select|Wrap|Line Numbers
  1. double erfc(double x)
  2. {
  3.     double t, u, y;
  4.  
  5.     t = 3.97886080735226 / (fabs(x) + 3.97886080735226);
  6.     u = t - 0.5;
  7.     y = (((((((((0.00127109764952614092 * u + 1.19314022838340944e-4) * u - 
  8.         0.003963850973605135) * u - 8.70779635317295828e-4) * u + 
  9.         0.00773672528313526668) * u + 0.00383335126264887303) * u - 
  10.         0.0127223813782122755) * u - 0.0133823644533460069) * u + 
  11.         0.0161315329733252248) * u + 0.0390976845588484035) * u + 
  12.         0.00249367200053503304;
  13.     y = ((((((((((((y * u - 0.0838864557023001992) * u - 
  14.         0.119463959964325415) * u + 0.0166207924969367356) * u + 
  15.         0.357524274449531043) * u + 0.805276408752910567) * u + 
  16.         1.18902982909273333) * u + 1.37040217682338167) * u + 
  17.         1.31314653831023098) * u + 1.07925515155856677) * u + 
  18.         0.774368199119538609) * u + 0.490165080585318424) * u + 
  19.         0.275374741597376782) * t * exp(-x * x);
  20.     return x < 0 ? 2 - y : y;
  21. }
Thanks
Feb 13 '13 #1
2 4580
donbock
2,426 Recognized Expert Top Contributor
Expand|Select|Wrap|Line Numbers
  1. return x < 0 ? 2-y : y;
is equivalent to
Expand|Select|Wrap|Line Numbers
  1. if (x < 0)
  2.    a = 2-y;
  3. else
  4.    a = y;
  5. return a;
x < 0 ? 2-y ? y is called a conditional expression.
The ? operator is called the ternary operator.

Personally, I don't find much use for the ternary operator in the code that I write.
Feb 13 '13 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
The idea behind the ternary operator comes from the old days when computers had very little memory. Generally, the less code you write, the less instructions are generated by the compiler. The ternary operator was an attempt to generate the least amout of code in the executable.

And ditto, I don't use it either.
Feb 13 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

32
8768
by: Mike Machuidel | last post by:
Hi, I'm a game developer programming mostly in C and ASM for about 7 years. Today at work a colleague (a C++ programmer) yelled at me I'm a bad C programmer because I use "return(0);" instead...
72
4124
by: Paminu | last post by:
In math this expression: (a < b) && (b < c) would be described as: a < b < c But why is it that in C these two expressions evaluate to something different for the same values of a, b and...
4
1489
by: Alex Sedow | last post by:
Method invocation will consist of the following steps: 1. Member lookup (14.3) - evaluate method group set (Base.f() and Derived.f()) .Standart say: "The compile-time processing of a method...
6
17058
by: murgan | last post by:
Hi people, i am new to this group,this is my first query, friends i want to know the difference between "function pointer" and "pointer to a function" in c lang, so friends please send the...
2
1833
by: Manuel | last post by:
In example, here: ------------------------- namespace Gooey Button::Button(Window* aParent, const std::string& aText, BasicButtonGroup* aGroup) : BasicButton(aParent, aText, aGroup) { }...
40
3089
by: Mark P | last post by:
I'm implementing an algorithm and the computational flow is a somewhat deep. That is, fcn A makes many calls to fcn B which makes many calls to fcn C, and so on. The return value of the outermost...
32
2159
by: Axel Bock | last post by:
Hi all, I am trying to get my head around what happens if I return a class object from a function. It seems C++ (MinGW) does not invoke the copy constructor if I do something like this: ...
4
1309
by: yaru22 | last post by:
In one of the examples in the book I'm reading, it says: def __init__(self): ... ... ... return It has nothing after "return". I expected it to have some number like 0 or 1.
36
2553
by: Pat | last post by:
Hi, I've run into a strange problem, but one that seems like it might be fairly common. I have a single base class, from which several other classes are derived. To keep the example simple,...
13
7762
by: Steve | last post by:
On page 392 of "Javascript the definitive guide" a function is called like this:- <form action="processform.cgi" onsubmit="return validateForm();"> Why, in this instance, is the return...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7330
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.