fixed clang++ and g++ c++11 "narrowing convertion" compilation errors

Just explicit casts where necessary for C++11.