I don’t actually need to use this in-game or anything, but I’ve been making a math module for fun to help one of my friends that is taking trig.
But having my answers come out as irrational decimals is really annoying for some things when I just want to have the EXACT answer.
So instead of having math.cos(math.rad(45)) → 0.7071…
Ideally I’d rather have it be math.cos(math.rad(45)) → √2 / 2
Well the thing with decimal for anythings is that rhey are not infinite, so if you want to convert it into a root you would also have to estimate. also that the problem you just said could be 1/sqrt(2) rather than sqrt(2)/2. It would be hard, but I really think its possible. I am not smart enough to know how.
This stackoverflow topic might be of some interest.
However, it’s worth noting that most values of cos(x) are transcendental, so you won’t always be able to express them as a “nice” fraction like sqrt(2)/2.
I looked through all the resources I could find and it seems that the best I can do is a taylor series, which is just an aprroximation (although a very good one) but not exact! I COULD try to use a look up table and compare the number I got with that and just say its very close to some specific number but that sounds like a bandaid solution.
The mathematician in me is itching for a clean, simple solution but it’s pretty obvious that millions of other people have tried and proven that you can’t. That’s a bummer.