PrecisionConstant

PrecisionConstant

PrecisionConstant[ value, n ] represents a number rounded to n decimals, which also stands for all values that round to it.

Usages

PrecisionConstant[ value, n ]

PrecisionConstant[ value, n ] is displayed as value with exactly n decimals. It represents every number that rounds to that value, so it can be used for measured or rounded values. Calculations keep track of the precision, and when an answer is compared with a PrecisionConstant, any value within its precision matches. Approximate creates a PrecisionConstant from any numerical value.

Example in displayed
Two decimals: 3.1 is displayed as 3.10. PrecisionConstant[ 3.1, 2 ] 3.103.10
The value is rounded to n decimals for display. PrecisionConstant[ 3.14159, 2 ] 3.143.14
Calculations keep the precision. CalcPlus[ PrecisionConstant[3.14, 2], 1 ] 4.144.14
Example in out
3.1415 rounds to 3.14, so it matches. IsMatch[ PrecisionConstant[3.14, 2], 3.1415, Method=>accuracy ] True
Options

LowerBound and UpperBound

Set the range of values that the number represents explicitly, instead of deriving it from the rounding. The upper bound is not included.

Syntax Example out
PrecisionConstant[ value, n, LowerBound=>a, UpperBound=>b ] IsMatch[ PrecisionConstant[2.2, 1, LowerBound=>2.1, UpperBound=>2.3], 2.25, Method=>accuracy ] True
IsMatch[ PrecisionConstant[2.2, 1, LowerBound=>2.1, UpperBound=>2.3], 2.35, Method=>accuracy ] False

Precision

Give the number of significant digits instead of the number of decimals; the second argument is then left out.

Syntax Example displayed
PrecisionConstant[ value, Precision=>p ] PrecisionConstant[ 1234, Precision=>2 ] 12×10212\times 10^{2}
Details
  • Without n: PrecisionConstant[ 3.14 ] is just the number 3.14.
  • value must be a number: PrecisionConstant[ x, 2 ] is left unevaluated.
Invalid input Result
PrecisionConstant[ 3.14, 2, Foo=>1 ] Error: Invalid associative argument for PrecisionConstant: Foo
Warning

== does not consider a PrecisionConstant equal to an ordinary number: PrecisionConstant[3.14159, 2] == 3.14 is False. Use IsMatch with Method=>accuracy to check whether a value is within the precision.

See also: Approximate, Precision, IsMatch, Numerical