begin ruby functions to calculate EC math