Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of a comma in a number [duplicate]

Tags:

c++

numbers

Possible Duplicate:
C++ Comma Operator

that probably a trivial question, but I don't know the answer. And this has been troubling me this afternoon.

I was just writing a function to convert RVB to YUV. Nothing really special, but mistakenly used the comma (,) instead of a dot in my numbers.

It compiles but the result was not what I expected, for example "-3713796" instead of a 0-255 range number.

(0,615*(double) 61) - (0,51498*(double) 61) - (0,10001*(double) 61)

So what does it mean ?
If it's not a compilation error, it's probably usefull for something but what?

Ps: I was using C++ with Qt.

like image 491
Matthieu Riegler Avatar asked Feb 21 '23 20:02

Matthieu Riegler


1 Answers

You've accidentally used the comma operator. It evaluates its first operand and discards the result, and then evaluates the second operand and returns its value and type.

In my experience, it's most commonly used in loop statements. For other uses, see Uses of C comma operator

like image 178
NPE Avatar answered Mar 08 '23 06:03

NPE