5

Mysterious behavior of Precision:

{{1.0+I*0.0},{0.0+I*0.0}} // SetPrecision[#,30]& // Precision // Print;
0.
{{1.0},{0.0}} // SetPrecision[#,30]& // Precision // Print;
30.

Why is the precision zero in the first instance, but not the second?

This led to some tough-to-diagnose program behaviors!

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
  • 1
  • 1
    It seems like the 0.0+I*0.0 is the culprit. Try I // SetPrecision[#, 30] & // Precision, 1 // SetPrecision[#, 30] & // Precision, 0 // SetPrecision[#, 30] & // Precision, 0.0 // SetPrecision[#, 30] & // Precision, 0.0 I // SetPrecision[#, 30] & // Precision and especially pay attention to the last two. I assume that Precision when applied to an array takes the minimum of the precisions of the elements of the array; the first element of {{1.0+I*0.0},{0.0+I*0.0}} has precision 30, whereas the second has precision 0, so the result is 0, but I'm not sure why 0.0I has precision 0. – DumpsterDoofus Feb 11 '14 at 00:35
  • And there's also precision Infinity: f[x_] := x // SetPrecision[#, 30] & // Precision; {f[0], f[0.0], f[0.0 + 0.0 I], f[1.0], f[1.0 I]} gives {[Infinity], [Infinity], 0., 30., 30.} – bill s Feb 11 '14 at 01:43

1 Answers1

1

Not receiving an answer, the following "workaround" returns Precision as a rounded-up integer multiple of MachinePrecision:

Precision$TNS[arg_] := arg//
  Precision//
    Which[
        NumberQ[#] && (#>0.0),
        {#},
        True,
        {arg}//Flatten//
          Map[Precision,#]&//
            Select[#,(NumberQ[#] && (#>0.0))&]&
    ]&//Max[#,MachinePrecision]&//
      (#-1)/MachinePrecision&//Ceiling//
        #*MachinePrecision&;
This workaround suffices (seemingly) for my main purpose, which is to assess and if necessary adaptively increase the precision of large-condition Real and Complex array arguments that are supplied to SingularValueDecomposition[_].