模板:Order of magnitude

模板页面
文档图示 模板文档[查看] [编辑] [查看历史] [清除缓存]

使用方法

This template calculates the (decimal) order of magnitude of numbers within the ranges 10300 to 10−300 and −10−300 to −10300.

The acceptable input and the output produced are optimised for use in other templates.

  • The hyphen (not a true minus sign) is used for negative numbers.
  • No separator is used for thousands.
  • The template gives 0 for 0. Although, strictly speaking, this is mathematically incorrect it has been designed this way so as to be more useful in other templates. An important example of this is that when used by 模板链接:{{convert}} 0 °C or 0 °F is considered to be on the same order of magnitude as ±1 °C or ±1 °F respectively.

范例

  • {{Order of magnitude|123400}} → 5 [1]
  • {{Order of magnitude|12340}} → 4 [2]
  • {{Order of magnitude|1234}} → 3 [3]
  • {{Order of magnitude|123.4}} → 2 [4]
  • {{Order of magnitude|12.34}} → 1 [5]
  • {{Order of magnitude|1.234}} → 0 [6]
  • {{Order of magnitude|.1234}} → -1 [7]
  • {{Order of magnitude|.01234}} → -2 [8]
  • {{Order of magnitude|0}} → 0 [9]
  • {{Order of magnitude}}表达式错误:预期外的=运算符。

错误用法

The input must be an unformatted number, or the template will emit errors:

  • {{Order of magnitude|}}Expression error: Unexpected = operator
  • {{Order of magnitude|123,400}}Expression error: Unrecognised punctuation character ","
  • {{Order of magnitude|foo}}Expression error: Unrecognised word "foo"

技术要点

This template calculates the order of magnitude of a number, using the natural logarithm of the absolute value of the number, divided by the log of 10. The amount is adjusted for truncation error in the digital format, and the floor number of the results is used. The magnitude of fractions, such as 0+1/1000 (-3), will also be calculated. The code uses four expansion-depth levels.

模板数据

Order of magnitude模板数据

This template calculates the order of magnitude of numbers within the ranges 10^300 to 10^−300 and −10^−300 to −10^300.

模板参数[编辑模板数据]

参数描述类型状态
Number1

The number to find the order of magnitude of

数字必需
上述文档内容嵌入自Template:Order of magnitude/doc编辑 | 历史
编者可以在本模板的沙盒创建 | 镜像和测试样例创建页面进行实验。
请将模板自身所属的分类添加在文档中。本模板的子页面