math.asciidoc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[sql-functions-math]]
  4. === Math Functions
  5. All math and trigonometric functions require their input (where applicable)
  6. to be numeric.
  7. ==== Generic
  8. [[sql-functions-math-abs]]
  9. ===== `ABS`
  10. .Synopsis:
  11. [source, sql]
  12. --------------------------------------------------
  13. ABS(numeric_exp<1>)
  14. --------------------------------------------------
  15. *Input*:
  16. <1> numeric expression
  17. *Output*: numeric
  18. .Description:
  19. Returns the https://en.wikipedia.org/wiki/Absolute_value[absolute value] of `numeric_exp`. The return type is the same as the input type.
  20. ["source","sql",subs="attributes,macros"]
  21. --------------------------------------------------
  22. include-tagged::{sql-specs}/docs.csv-spec[abs]
  23. --------------------------------------------------
  24. [[sql-functions-math-cbrt]]
  25. ===== `CBRT`
  26. .Synopsis:
  27. [source, sql]
  28. --------------------------------------------------
  29. CBRT(numeric_exp<1>)
  30. --------------------------------------------------
  31. *Input*:
  32. <1> numeric expression
  33. *Output*: double numeric value
  34. .Description:
  35. Returns the https://en.wikipedia.org/wiki/Cube_root[cube root] of `numeric_exp`.
  36. ["source","sql",subs="attributes,macros"]
  37. --------------------------------------------------
  38. include-tagged::{sql-specs}/docs.csv-spec[mathInlineCbrtWithNegativeValue]
  39. --------------------------------------------------
  40. [[sql-functions-math-ceil]]
  41. ===== `CEIL/CEILING`
  42. .Synopsis:
  43. [source, sql]
  44. --------------------------------------------------
  45. CEIL(numeric_exp<1>)
  46. CEILING(numeric_exp<2>)
  47. --------------------------------------------------
  48. *Input*:
  49. <1> numeric expression
  50. <2> numeric expression
  51. *Output*: integer or long numeric value
  52. .Description:
  53. Returns the smallest integer greater than or equal to `numeric_exp`.
  54. ["source","sql",subs="attributes,macros"]
  55. --------------------------------------------------
  56. include-tagged::{sql-specs}/docs.csv-spec[mathInlineCeiling]
  57. --------------------------------------------------
  58. [[sql-functions-math-e]]
  59. ===== `E`
  60. .Synopsis:
  61. [source, sql]
  62. --------------------------------------------------
  63. E()
  64. --------------------------------------------------
  65. *Input*: _none_
  66. *Output*: `2.718281828459045`
  67. .Description:
  68. Returns https://en.wikipedia.org/wiki/E_%28mathematical_constant%29[Euler's number].
  69. ["source","sql",subs="attributes,macros"]
  70. --------------------------------------------------
  71. include-tagged::{sql-specs}/docs.csv-spec[mathEulersNumber]
  72. --------------------------------------------------
  73. [[sql-functions-math-exp]]
  74. ===== `EXP`
  75. .Synopsis:
  76. [source, sql]
  77. --------------------------------------------------
  78. EXP(numeric_exp<1>)
  79. --------------------------------------------------
  80. *Input*:
  81. <1> float numeric expression
  82. *Output*: double numeric value
  83. .Description:
  84. Returns https://en.wikipedia.org/wiki/Exponential_function[Euler's number at the power] of `numeric_exp` e^numeric_exp^.
  85. ["source","sql",subs="attributes,macros"]
  86. --------------------------------------------------
  87. include-tagged::{sql-specs}/docs.csv-spec[mathExpInline]
  88. --------------------------------------------------
  89. [[sql-functions-math-expm1]]
  90. ===== `EXPM1`
  91. .Synopsis:
  92. [source, sql]
  93. --------------------------------------------------
  94. EXPM1(numeric_exp<1>)
  95. --------------------------------------------------
  96. *Input*:
  97. <1> float numeric expression
  98. *Output*: double numeric value
  99. .Description:
  100. Returns https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#expm1-double-[Euler's number at the power] of `numeric_exp` minus 1 (e^numeric_exp^ - 1).
  101. ["source","sql",subs="attributes,macros"]
  102. --------------------------------------------------
  103. include-tagged::{sql-specs}/docs.csv-spec[mathExpm1Inline]
  104. --------------------------------------------------
  105. [[sql-functions-math-floor]]
  106. ===== `FLOOR`
  107. .Synopsis:
  108. [source, sql]
  109. --------------------------------------------------
  110. FLOOR(numeric_exp<1>)
  111. --------------------------------------------------
  112. *Input*:
  113. <1> numeric expression
  114. *Output*: integer or long numeric value
  115. .Description:
  116. Returns the largest integer less than or equal to `numeric_exp`.
  117. ["source","sql",subs="attributes,macros"]
  118. --------------------------------------------------
  119. include-tagged::{sql-specs}/docs.csv-spec[mathInlineFloor]
  120. --------------------------------------------------
  121. [[sql-functions-math-log]]
  122. ===== `LOG`
  123. .Synopsis:
  124. [source, sql]
  125. --------------------------------------------------
  126. LOG(numeric_exp<1>)
  127. --------------------------------------------------
  128. *Input*:
  129. <1> numeric expression
  130. *Output*: double numeric value
  131. .Description:
  132. Returns the https://en.wikipedia.org/wiki/Natural_logarithm[natural logarithm] of `numeric_exp`.
  133. ["source","sql",subs="attributes,macros"]
  134. --------------------------------------------------
  135. include-tagged::{sql-specs}/docs.csv-spec[mathInlineLog]
  136. --------------------------------------------------
  137. [[sql-functions-math-log10]]
  138. ===== `LOG10`
  139. .Synopsis:
  140. [source, sql]
  141. --------------------------------------------------
  142. LOG10(numeric_exp<1>)
  143. --------------------------------------------------
  144. *Input*:
  145. <1> numeric expression
  146. *Output*: double numeric value
  147. .Description:
  148. Returns the https://en.wikipedia.org/wiki/Common_logarithm[base 10 logarithm] of `numeric_exp`.
  149. ["source","sql",subs="attributes,macros"]
  150. --------------------------------------------------
  151. include-tagged::{sql-specs}/docs.csv-spec[mathInlineLog10]
  152. --------------------------------------------------
  153. [[sql-functions-math-pi]]
  154. ===== `PI`
  155. .Synopsis:
  156. [source, sql]
  157. --------------------------------------------------
  158. PI()
  159. --------------------------------------------------
  160. *Input*: _none_
  161. *Output*: `3.141592653589793`
  162. .Description:
  163. Returns https://en.wikipedia.org/wiki/Pi[PI number].
  164. ["source","sql",subs="attributes,macros"]
  165. --------------------------------------------------
  166. include-tagged::{sql-specs}/docs.csv-spec[mathPINumber]
  167. --------------------------------------------------
  168. [[sql-functions-math-power]]
  169. ===== `POWER`
  170. .Synopsis:
  171. [source, sql]
  172. --------------------------------------------------
  173. POWER(numeric_exp<1>, integer_exp<2>)
  174. --------------------------------------------------
  175. *Input*:
  176. <1> numeric expression
  177. <2> integer expression
  178. *Output*: double numeric value
  179. .Description:
  180. Returns the value of `numeric_exp` to the power of `integer_exp`.
  181. ["source","sql",subs="attributes,macros"]
  182. --------------------------------------------------
  183. include-tagged::{sql-specs}/docs.csv-spec[mathInlinePowerPositive]
  184. --------------------------------------------------
  185. ["source","sql",subs="attributes,macros"]
  186. --------------------------------------------------
  187. include-tagged::{sql-specs}/docs.csv-spec[mathInlinePowerNegative]
  188. --------------------------------------------------
  189. [[sql-functions-math-round]]
  190. ===== `ROUND`
  191. .Synopsis:
  192. [source, sql]
  193. ----
  194. ROUND(numeric_exp<1>[, integer_exp<2>])
  195. ----
  196. *Input*:
  197. <1> numeric expression
  198. <2> integer expression; optional
  199. *Output*: numeric
  200. .Description:
  201. Returns `numeric_exp` rounded to `integer_exp` places right of the decimal point. If `integer_exp` is negative,
  202. `numeric_exp` is rounded to |`integer_exp`| places to the left of the decimal point. If `integer_exp` is omitted,
  203. the function will perform as if `integer_exp` would be 0. The returned numeric data type is the same as the data type
  204. of `numeric_exp`.
  205. ["source","sql",subs="attributes,macros"]
  206. --------------------------------------------------
  207. include-tagged::{sql-specs}/docs.csv-spec[mathRoundWithPositiveParameter]
  208. --------------------------------------------------
  209. ["source","sql",subs="attributes,macros"]
  210. --------------------------------------------------
  211. include-tagged::{sql-specs}/docs.csv-spec[mathRoundWithNegativeParameter]
  212. --------------------------------------------------
  213. [[sql-functions-math-sign]]
  214. ===== `SIGN`
  215. .Synopsis:
  216. [source, sql]
  217. --------------------------------------------------
  218. SIGN(numeric_exp<1>)
  219. --------------------------------------------------
  220. *Input*:
  221. <1> numeric expression
  222. *Output*: [-1, 0, 1]
  223. .Description:
  224. Returns an indicator of the sign of `numeric_exp`. If `numeric_exp` is less than zero, –1 is returned. If `numeric_exp` equals zero, 0 is returned. If `numeric_exp` is greater than zero, 1 is returned.
  225. ["source","sql",subs="attributes,macros"]
  226. --------------------------------------------------
  227. include-tagged::{sql-specs}/docs.csv-spec[mathInlineSign]
  228. --------------------------------------------------
  229. [[sql-functions-math-sqrt]]
  230. ===== `SQRT`
  231. .Synopsis:
  232. [source, sql]
  233. --------------------------------------------------
  234. SQRT(numeric_exp<1>)
  235. --------------------------------------------------
  236. *Input*:
  237. <1> numeric expression
  238. *Output*: double numeric value
  239. .Description:
  240. Returns https://en.wikipedia.org/wiki/Square_root[square root] of `numeric_exp`.
  241. ["source","sql",subs="attributes,macros"]
  242. --------------------------------------------------
  243. include-tagged::{sql-specs}/docs.csv-spec[mathInlineSqrt]
  244. --------------------------------------------------
  245. [[sql-functions-math-truncate]]
  246. ===== `TRUNCATE`
  247. .Synopsis:
  248. [source, sql]
  249. ----
  250. TRUNCATE(numeric_exp<1>[, integer_exp<2>])
  251. ----
  252. *Input*:
  253. <1> numeric expression
  254. <2> integer expression; optional
  255. *Output*: numeric
  256. .Description:
  257. Returns `numeric_exp` truncated to `integer_exp` places right of the decimal point. If `integer_exp` is negative,
  258. `numeric_exp` is truncated to |`integer_exp`| places to the left of the decimal point. If `integer_exp` is omitted,
  259. the function will perform as if `integer_exp` would be 0. The returned numeric data type is the same as the data type
  260. of `numeric_exp`.
  261. ["source","sql",subs="attributes,macros"]
  262. --------------------------------------------------
  263. include-tagged::{sql-specs}/docs.csv-spec[mathTruncateWithPositiveParameter]
  264. --------------------------------------------------
  265. ["source","sql",subs="attributes,macros"]
  266. --------------------------------------------------
  267. include-tagged::{sql-specs}/docs.csv-spec[mathTruncateWithNegativeParameter]
  268. --------------------------------------------------
  269. ==== Trigonometric
  270. [[sql-functions-math-acos]]
  271. ===== `ACOS`
  272. .Synopsis:
  273. [source, sql]
  274. --------------------------------------------------
  275. ACOS(numeric_exp<1>)
  276. --------------------------------------------------
  277. *Input*:
  278. <1> numeric expression
  279. *Output*: double numeric value
  280. .Description:
  281. Returns the https://en.wikipedia.org/wiki/Inverse_trigonometric_functions[arccosine] of `numeric_exp` as an angle, expressed in radians.
  282. ["source","sql",subs="attributes,macros"]
  283. --------------------------------------------------
  284. include-tagged::{sql-specs}/docs.csv-spec[mathInlineAcos]
  285. --------------------------------------------------
  286. [[sql-functions-math-asin]]
  287. ===== `ASIN`
  288. .Synopsis:
  289. [source, sql]
  290. --------------------------------------------------
  291. ASIN(numeric_exp<1>)
  292. --------------------------------------------------
  293. *Input*:
  294. <1> numeric expression
  295. *Output*: double numeric value
  296. .Description:
  297. Returns the https://en.wikipedia.org/wiki/Inverse_trigonometric_functions[arcsine] of `numeric_exp` as an angle, expressed in radians.
  298. ["source","sql",subs="attributes,macros"]
  299. --------------------------------------------------
  300. include-tagged::{sql-specs}/docs.csv-spec[mathInlineAsin]
  301. --------------------------------------------------
  302. [[sql-functions-math-atan]]
  303. ===== `ATAN`
  304. .Synopsis:
  305. [source, sql]
  306. --------------------------------------------------
  307. ATAN(numeric_exp<1>)
  308. --------------------------------------------------
  309. *Input*:
  310. <1> numeric expression
  311. *Output*: double numeric value
  312. .Description:
  313. Returns the https://en.wikipedia.org/wiki/Inverse_trigonometric_functions[arctangent] of `numeric_exp` as an angle, expressed in radians.
  314. ["source","sql",subs="attributes,macros"]
  315. --------------------------------------------------
  316. include-tagged::{sql-specs}/docs.csv-spec[mathInlineAtan]
  317. --------------------------------------------------
  318. [[sql-functions-math-atan2]]
  319. ===== `ATAN2`
  320. .Synopsis:
  321. [source, sql]
  322. --------------------------------------------------
  323. ATAN2(ordinate<1>, abscisa<2>)
  324. --------------------------------------------------
  325. *Input*:
  326. <1> numeric expression
  327. <2> numeric expression
  328. *Output*: double numeric value
  329. .Description:
  330. Returns the https://en.wikipedia.org/wiki/Atan2[arctangent of the `ordinate` and `abscisa` coordinates] specified as an angle, expressed in radians.
  331. ["source","sql",subs="attributes,macros"]
  332. --------------------------------------------------
  333. include-tagged::{sql-specs}/docs.csv-spec[mathInlineAtan2]
  334. --------------------------------------------------
  335. [[sql-functions-math-cos]]
  336. ===== `COS`
  337. .Synopsis:
  338. [source, sql]
  339. --------------------------------------------------
  340. COS(numeric_exp<1>)
  341. --------------------------------------------------
  342. *Input*:
  343. <1> numeric expression
  344. *Output*: double numeric value
  345. .Description:
  346. Returns the https://en.wikipedia.org/wiki/Trigonometric_functions#cosine[cosine] of `numeric_exp`, where `numeric_exp` is an angle expressed in radians.
  347. ["source","sql",subs="attributes,macros"]
  348. --------------------------------------------------
  349. include-tagged::{sql-specs}/docs.csv-spec[mathInlineCosine]
  350. --------------------------------------------------
  351. [[sql-functions-math-cosh]]
  352. ===== `COSH`
  353. .Synopsis:
  354. [source, sql]
  355. --------------------------------------------------
  356. COSH(numeric_exp<1>)
  357. --------------------------------------------------
  358. *Input*:
  359. <1> numeric expression
  360. *Output*: double numeric value
  361. .Description:
  362. Returns the https://en.wikipedia.org/wiki/Hyperbolic_function[hyperbolic cosine] of `numeric_exp`.
  363. ["source","sql",subs="attributes,macros"]
  364. --------------------------------------------------
  365. include-tagged::{sql-specs}/docs.csv-spec[mathInlineCosh]
  366. --------------------------------------------------
  367. [[sql-functions-math-cot]]
  368. ===== `COT`
  369. .Synopsis:
  370. [source, sql]
  371. --------------------------------------------------
  372. COT(numeric_exp<1>)
  373. --------------------------------------------------
  374. *Input*:
  375. <1> numeric expression
  376. *Output*: double numeric value
  377. .Description:
  378. Returns the https://en.wikipedia.org/wiki/Trigonometric_functions#Cosecant,_secant,_and_cotangent[cotangent] of `numeric_exp`, where `numeric_exp` is an angle expressed in radians.
  379. ["source","sql",subs="attributes,macros"]
  380. --------------------------------------------------
  381. include-tagged::{sql-specs}/docs.csv-spec[mathInlineCotangent]
  382. --------------------------------------------------
  383. [[sql-functions-math-degrees]]
  384. ===== `DEGREES`
  385. .Synopsis:
  386. [source, sql]
  387. --------------------------------------------------
  388. DEGREES(numeric_exp<1>)
  389. --------------------------------------------------
  390. *Input*:
  391. <1> numeric expression
  392. *Output*: double numeric value
  393. .Description:
  394. Convert from https://en.wikipedia.org/wiki/Radian[radians]
  395. to https://en.wikipedia.org/wiki/Degree_(angle)[degrees].
  396. ["source","sql",subs="attributes,macros"]
  397. --------------------------------------------------
  398. include-tagged::{sql-specs}/docs.csv-spec[mathInlineDegrees]
  399. --------------------------------------------------
  400. [[sql-functions-math-radians]]
  401. ===== `RADIANS`
  402. .Synopsis:
  403. [source, sql]
  404. --------------------------------------------------
  405. RADIANS(numeric_exp<1>)
  406. --------------------------------------------------
  407. *Input*:
  408. <1> numeric expression
  409. *Output*: double numeric value
  410. .Description:
  411. Convert from https://en.wikipedia.org/wiki/Degree_(angle)[degrees]
  412. to https://en.wikipedia.org/wiki/Radian[radians].
  413. ["source","sql",subs="attributes,macros"]
  414. --------------------------------------------------
  415. include-tagged::{sql-specs}/docs.csv-spec[mathInlineRadians]
  416. --------------------------------------------------
  417. [[sql-functions-math-sin]]
  418. ===== `SIN`
  419. .Synopsis:
  420. [source, sql]
  421. --------------------------------------------------
  422. SIN(numeric_exp<1>)
  423. --------------------------------------------------
  424. *Input*:
  425. <1> numeric expression
  426. *Output*: double numeric value
  427. .Description:
  428. Returns the https://en.wikipedia.org/wiki/Trigonometric_functions#sine[sine] of `numeric_exp`, where `numeric_exp` is an angle expressed in radians.
  429. ["source","sql",subs="attributes,macros"]
  430. --------------------------------------------------
  431. include-tagged::{sql-specs}/docs.csv-spec[mathInlineSine]
  432. --------------------------------------------------
  433. [[sql-functions-math-sinh]]
  434. ===== `SINH`
  435. .Synopsis:
  436. [source, sql]
  437. --------------------------------------------------
  438. SINH(numeric_exp<1>)
  439. --------------------------------------------------
  440. *Input*:
  441. <1> numeric expression
  442. *Output*: double numeric value
  443. .Description:
  444. Returns the https://en.wikipedia.org/wiki/Hyperbolic_function[hyperbolic sine] of `numeric_exp`.
  445. ["source","sql",subs="attributes,macros"]
  446. --------------------------------------------------
  447. include-tagged::{sql-specs}/docs.csv-spec[mathInlineSinh]
  448. --------------------------------------------------
  449. [[sql-functions-math-tan]]
  450. ===== `TAN`
  451. .Synopsis:
  452. [source, sql]
  453. --------------------------------------------------
  454. TAN(numeric_exp<1>)
  455. --------------------------------------------------
  456. *Input*:
  457. <1> numeric expression
  458. *Output*: double numeric value
  459. .Description:
  460. Returns the https://en.wikipedia.org/wiki/Trigonometric_functions#tangent[tangent] of `numeric_exp`, where `numeric_exp` is an angle expressed in radians.
  461. ["source","sql",subs="attributes,macros"]
  462. --------------------------------------------------
  463. include-tagged::{sql-specs}/docs.csv-spec[mathInlineTanget]
  464. --------------------------------------------------