I used a program developed by Formedia for low pressure gas pipe sizing. I checked the output by comparing it to the UPC and IFGC tables. The program’s output matched the code tables to my satisfaction. The formula and constants referenced in the program documentation are Codes B149.1-M91 and B149.1-00 for natural gas and B149.2-M91 for propane.
As I recall, the program was very inexpensive, and as such, it may not be worth your time to re-invent the wheel.