trying to find absolute value and i thought there was a simple way to just invert the sign with '~' or something.
<< is the left shift operator. It is shifting the number 1 to the left 0 bits, which is equivalent to the number 1 .
Abs. If you want to remove the sign from a string, you can use math. Abs, or String.
The short answer is: for a numerical literal with a decimal point, a suffix of f or F will tell the compiler your numerical literal should be taken as a float number, instead of as a double ; it will be taken as a long double if the suffix is l or L .
Of course you can add an int to float . C will convert the int to float before adding. However, in the expression (float)15/2 + 15/2 , the first 15/2 will be calculated as float and the second 15/2 will be an integer division first, and that result converted to float. So you'll be adding 7.5+7.
float newValue = oldValue * -1;
or
float newValue = -(oldValue); //() aren't needed, I just use them out of habit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With