Cast tail arithmetic

Casting arithmetic prevents problems with long longs