I was wondering if it's OK to ask about the implementation of a mathematical function in code?
Really do not know if I should ask in StackOverflow or math.stackexchange.
My view has always been that programming questions are very much borderline. Here is the border, as I see it.
Your question is about the mathematics of the algorithm. This could be about a specific implementation, but the question has to be mathematical. That question is on-topic here.
Your question is about the implementation of your code. It is about the language, your use of the language, or some problems related to the process of implementing the algorithm, rather than its design. This question is not on-topic here and should be asked elsewhere.