There's work on tool-assisted LMs regarding math problems: https://arxiv.org/abs/2305.15017. TL;DR: they train the LM to extract the numbers, then feed it into an calculator and return back the result to the LM during inference.
Vanilla LMs, which are neural nets, don't compute anything - they guess the result. The guess is based on previously seen distribution of results related to the given problem. I saw a paper that explored the distribution but can't find it anywhere...