I have a unit vector $N$ which is the normal to some flat surface. I want to generate two other unit vectors $U$ and $V$ which are mutually perpendicular and lie in this surface, so $(N,U,V)$ will be a set of basis vectors. It does not matter how $U$ and $V$ are rotationally oriented.
In principle I can choose an arbitrary unit vector $M \neq N$ and take cross-products, but this isn't numerically stable in all cases.
Example of something which will not work, choosing $M=N+(1,0,0)^T$, because in the special case that $M=(1,0,0)^T$, the cross products will degenerate.
I can tweak this algorithm with suitable checks, obviously, but this will run on embedded hardware which doesn't handle conditional branches very well and performance is an issue.
Is there a numerically-stable, non-branching algorithm for picking $U$ and $V$ given $N$?