This was the problem in a Perl Golf contest a long, long time ago. There were a couple of minor differences in the spec (trillions didn't need to be handled, the result needed to be pretty-printed with thousand-separator commas).
The explanation by Ton Hospel of the winning solution of 115 characters and the later improvement to 109 chars is a thing of beauty: http://www.mail-archive.com/golf@perl.org/msg01568.html