Finished the calculate_t function. I tested it against my JavaScript
version of the function and got a slightly different result:

JavaScript: t = 388
C         : t = 364

It's not a big difference but definitely not negligible. I will continue
to look into it after I have the other functions translated.