Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
ay23063256yfloat cal_y = ((float)(y2-y1)/(float)(x2-x1))*(float)(x) - ((float)(y2-y1)/(float)(x2-x1))*(float)x1 + (float)y1;
This shows how much i trust my compiler. -
inaba46256y@ay2306 Can't be entirely sure what comes out of the multiplications and divisions are floats. Also the final sums and differences aren't guarenteed to be a float either. Fixed it for you!
float cal_y = (float)((float)((float)((float)((float)y2-(float)y1)/(float)(x2-x1))*(float)(x)) - (float)(((float)(y2-y1)/(float)((float)x2-(float)x1))*(float)x1) + (float)y1); -
ay23063256y@inaba isn't division and addition of two floats also float? Why type comversion even beyond that?
-
You could try LISP - then you'll be so fed up with parentheses that you'll naturally hate them.
-
its already fast to write with a decent text editor tho. Bothering whether to write or not takes much more time than just inserting these parantheses.
-
The preprocessor macros in C justify this paranoia
#defne SQUARE(x) x*x
int a = 3;
int y = SQUARE(a+2);
// y = 3+2*3+2 = 11
// instead of (3+2)*(3+2) -
taglia5716y@Batburger those are not "redundant" parenthesis, just explicit.
redundant parenthesis are like these: ((a + b)) / 2.
I don't know if @inaba was talking about that fact, or about the fact that putting explicit parenthesis is better, since a lot of people seems to forget/ignore the operand priority rules.
As someone said, better be safe than sorry (for a misunderstanding) -
inaba46256y@taglia No @Batburger is right. The order of operations dictate that the outer most parenthesis are redundant
((b - a) / 2) + a => (b - a) / 2 + a
In postfix both expressions would give the same as well, which is
b a - 2 / a + -
taglia5716y@inaba had to check the full definition of redundant. For me was just "exact copy", that's why I said "explicit, not redundant".
My bad.
Btw, I didn't argue the logic, just the term. (even if I made a mistake 😂) -
joykill3436yWhen it comes to non essential parantheses, IMHO, readability is the most important factor... Do they help with reading the code? Jus add them
I always put redundant parentheses in formula like ((b - a) / 2) + a because I just don't trust the compiler.
rant