Thanks Anboo for the information.
John Patrick, not sure what your code looks like. You could just compute all values likely to get used and save them to a database or flat file. Then, all your program would need to do is a query if you use a database. You could use hashing otherwise.