avoid unnecessary casting int -> double -> int
fix compiler warning: no return statement in non-void function