Ported smartinterp(n) from glue.