Subject–Verb Inversion in Statements

Sometimes people will invert the subject–verb order in a sentence apparently for emphasis. One example that I love is that meme:

"The risk I took was calculated, but man, am I bad at math."

The "am I bad at math" part is inverted, but I can't find any grammatical explanation for that. Does this have any specific name? Is it grammatically correct to do it? If so, in any specific cases?