CIECAM02 is not easy… You may also have a look at the ciecam02 functions in RawTherapee. They are quite mature now and solve some special cases which are not solved in the original equations. I (and also @jdc) can point you to the relevant part of the source in case you’re interested.
Edit: for example this case is not handled in the original ciecam02 implementation: