I am currently writing a large module, called Math +. The idea is to create an alternative, more useful, math function table. It will include all the standard math functions, such as math.sin, etc.
I have implemented a system in which users can create complex numbers. It is OOP and its own number “class.” I have successfully implemented addition, subtraction, multiplication, and division of said complex numbers. These all, of course, use metamethods, such as __add, etc. However, I wish to implement modulus and exponentiation, which appear to be more sophisticated than the other operators that I made very easily.
I have tried searching the web for solutions, but I have yet to find an understandable (for me) way to achieve my goal. Essentially I want operators % and ^ to work on the complex numbers.
local n = Complex.new(1,3) -- this would be 1 + 3i
print(n ^ 2) -- should return -8 + 6i
print(n ^ n) -- should return -0.000705958477 - 0.0745795029i
print(n % 2) -- should return 1 + i
print(n % Complex.new(0,4)) -- -3 + 3i
These are just a few examples of the idea behind these operators. I do realize I could use a for loop for a complex number raised to an integer power. However, ideally I could include decimals as powers as well.
I am not in any way asking for someone to write code for me. If anyone knows how I could accomplish this, please provide an explanation, or even a link if you have time to research. Code written for me (if written and used) would be credited in the module forever, which I plan to release publicly once I believe it is sufficiently completed.
Edit: I am heading off for the night. I will respond to any responses in the morning. Thanks!
Thank you for reading. Please help you are able to. Have a great day!
- Galactiq