implemented ``cast`` scalar function