I wrote a C program to do this many years ago. They are hard, being complex arithmetic series approximations that have to be solved iteratively. I had to define my own structure to handle imaginary numbers and create the complex arithmetic operations. The equations are on the LINZ website to do this.
They also have an online calculator that is excellent.
Note that since NZMG used the geodetic datum 1949, which is a copy of the International Datum 1909 you will also have to do a datum shift to get to WGS84. That is also difficult unless you approximate it with a 3 or 7 parameter equation that gets you only within 15 metres or so. Otherwise you need to use a grid adjustment that gets you down to survey accuracy.
NZMG is obsolete and has not been used since 2000. You really only need a one-off conversion to upgrade to NZTM (a standard transverse mercator using the UTM equations) so I cannot see the need to write another conversion program. I have found my code! March 1993, you are welcome to have it.
Note that recent earthquakes in New Zealand have moved large parts by up to 2 metres, so there is a revision of the reference marks underway at the moment.