Hey guys, forgive me for posting something that probably has a smiple answer to but I'm confused. Why does the following produce a number such as 103249812 when my "y" is a negative number? even when intersection.getY() is a small number, like -74
drwbns wrote:I found that a simple equation like uint + int works fine but if I do (uint + int) / uint I have to change all vars to ints
In general, when performing a computation involving signed and unsigned integral types you should perform static_casts to unify the types, i.e. work with only one type. The exact rules for integral conversions are somewhat tricky, even implementation-defined -- you can check them at clause 4.7 from the ISO C++ specification.
My advice is to cast everything to the type you need; that way is always safe. You should check, however, that you don't loose precision when performing such conversions.