In terms of speed N
and SetPrecision
can be expected to be faster as they do not involve an unnecessary multiplication. (Conversely 2` * a
would be better than N[2 * a]
because the latter does exact multiplication before the conversion.)
1. a
and 1` a
can be considered identical because they represent the same input. Personally I have taken to using the latter form for entering machine-precision integers because the syntax better reminds me of the purpose.
One can see that N
and SetPrecision[#, MachinePrecision] &
are, if not equivalent, closely related. Observe:
N[thing] := 17.5
NValues[thing]
{HoldPattern[N[thing, {MachinePrecision, MachinePrecision}]] :> 17.5}
Now:
N[thing]
SetPrecision[thing, MachinePrecision]
17.5
17.5
The fact that NValues
output is given from SetPrecision
indicates to me that it is using a common mechanism.
On-the-fly conversion does not use NValues
:
1. thing
2` + thing
1. thing
2. + thing
Here is another demonstrable difference between N
/SetPrecision
and multiplication by 1.
:
N[ Exp[1000] ] // Precision
SetPrecision[Exp[1000], MachinePrecision] // Precision
1. Exp[1000] // Precision
12.9546
12.9546
15.9546
Developer`ToPackedArray[{1, Sqrt[2], 3, 4}, Real]
to create machine precision numbers. $\endgroup$