Weird rounding error in n and N
This is weird. While dabbling in sage, It seems I hit a rounding error.
sage: number=180*arccos(14/205*sqrt(41)*sqrt(5))/pi
sage: n(number)
12.0947570770121
sage: n(number,digits=4)
12.10
Is there any good reason that I'm not getting 12.09 as a result? This happens in N as well.
Here's my sage info.
SageMath version 9.2, Release Date: 2020-10-24
Using Python 3.9.5. Type "help()" for help.
Something fishy is going on here. If we take the numerical value directly. it's rounded correctly:
As a temporary workaround you can use
n(n(number),digits=4)
Same thing happens in CoCalc, running SageMath version 9.3
It may be possible that
digits=4
is applied to every term in the expression before it's evaluated, resulting in the loss of precision, like in:That's a solid hypothesis! I did find a better method:
This is probably how one should do it. I will however leave this post unanswered, as the original question is still not definitely answered.