thanks a lot!
Any set of the angles will do (just like returning q or -q is acceptable as well). If you want the other quaternion representing the Eulers, negate it.
I guess the reason for ambiguity is because of the call to asin (which returns angles only in a 180 degree (or pi radian) range), not the full range (because of how inverse functions work, they can only return one value).
Try adding pi on to the return from asin, you will probably get the other quaternion instead...(EDIT: asin(x + pi) != asin(x) so ignore that ;), the formula is asin(x + pi) = -asin(x), I think [too much beer])
(atan2 does return full 2pi radian range though).
I wouldn't worry about it though. Note the trig functions don't really have inverse functions (since a function can only return one value in the strict mathematical sense of the term), asin is a restirction of the "inverse" sin funtion so that it does have a unique inverse.
EDIT: Try thinking of it like this instead:
why doesn't sqrt(-1 * -1) return -1? Same deal.