Template:Num

From SacredWiki
Jump to navigation Jump to search

This template has as parameter an expression and produces a decimal number. If the expression produces a number of type integer, the template returns exactly that integer. If the expression produces a float, the template returns the result with a format that is accepted in an expression, and with an accuracy such the system would round it to the same float; thus if applied to a result of the template, the template returns the same.

The format (in the examples shown with Template:Numfh) is ordinary decimal format, because scientific notation with a fixed normalisation in general does not allow a representation of the exact float, see Help:Calculation accuracy#Reconstruction of an internal number.

For any float, 17 significant digits are enough to reconstruct it. Therefore we get for example:

  • {{numfh|(2-2^-52)*2^-20}} → .0000019073486328124997 (ca. 1.9e-6) 1.fffffffffffffhex*2^-20
  • {{numfh|(2-2^-52)*2^10}} → 2,047.9999999999998 (ca. 2e3) 1.fffffffffffffhex*2^10
  • {{numfh|(2-2^-52)*2^20}} → 2,097,151.9999999998 (ca. 2.1e6) 1.fffffffffffffhex*2^20

For numbers with a decimal point, trailing zeros are avoided:

  • {{numfh|1e-3/8}} → .000125 (ca. 1.3e-4) 1.0624dd2f1a9fchex*2^-13
  • {{numfh|1e-10/8}} → .0000000000125 (ca. 1.3e-11) 1.b7cdfd9d7bdbbhex*2^-37
  • {{numfh|1e-20/8}} → .0000000000000000000012499999999999999 (ca. 1.3e-21) 1.79ca10c924223hex*2^-70
  • {{numfh|.00000000000000000000125}} → .0000000000000000000012499999999999999 (ca. 1.3e-21) 1.79ca10c924223hex*2^-70

Large floats:

  • {{numfh|3^39}} → 4,052,555,153,018,976,256 (ca. 4.1e18) 1.c1ec8b85c2ffchex*2^61

Numbers of type integer have up to 19 digits:

  • {{numfh|trunc3^trunc39}} → 4,052,555,153,018,976,267 (ca. 4.1e18) 1.c1ec8b85c2ffchex*2^61


See also

  • Template:Numf - version with thousands separators; the output is suitable in expressions used as input of Template:Num etc., but not for #expr.
  • Template:Numfh - version with thousands separators producing also the type (integer or float), and the hexidecimal representation (exact in the case of float, approximate in the case of a large number of type integer); not suitable as input for further computations