# Improving working precision of LegendreP[n,x]? [duplicate]

I was trying to evaluate

N[LegendreP[5,0.1]]


The cell gives me:

N[LegendreP[5,0.1]]=0.178829


However I wanted more precision digits. I tried to use:

N[LegendreP[5,0.1],20]


But the result is the same. Interestingly, if I try with

 N[LegendreP[5,1],20]


The result showed significantly increased digits

1.0000000000000000000


Is there a way that we can evaluate LegendreP more accurately?

The reason is that you're using machine-precision input, so the result you get will always be machine precision.

N[LegendreP[5, 0.1], 20]

0.17882875

Precision /@ {0.1, 0.17882875}


{MachinePrecision, MachinePrecision}

To get result in arbitrary precision you can use exact input or non-machine precision input (which is what happened when you used the integer 1):

N[LegendreP[5, 1/10], 20]

0.17882875000000000000


Notice the following:

N[LegendreP[5, #], 18] & /@ {0.1000000000000000, 0.100000000000000000}

{0.17882875, 0.17882875000000000}


What happens here is that \$MachinePrecision returns 15.9545898` on my machine, so any input with less than or equal to 16 digits will result in Mathematica using machine-precision for the computation, whereas anything greater is considered arbitrary precision and will be treated as such. Which is why the first input with 16 digits (machine precision) ignored our request for arbitrary precision output.