math.asciidoc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  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-random]]
  190. ===== `RANDOM`
  191. .Synopsis:
  192. [source, sql]
  193. --------------------------------------------------
  194. RANDOM(seed<1>)
  195. --------------------------------------------------
  196. *Input*:
  197. <1> numeric expression
  198. *Output*: double numeric value
  199. .Description:
  200. Returns a random double using the given seed.
  201. ["source","sql",subs="attributes,macros"]
  202. --------------------------------------------------
  203. include-tagged::{sql-specs}/docs.csv-spec[mathRandom]
  204. --------------------------------------------------
  205. [[sql-functions-math-round]]
  206. ===== `ROUND`
  207. .Synopsis:
  208. [source, sql]
  209. ----
  210. ROUND(numeric_exp<1>[, integer_exp<2>])
  211. ----
  212. *Input*:
  213. <1> numeric expression
  214. <2> integer expression; optional
  215. *Output*: numeric
  216. .Description:
  217. Returns `numeric_exp` rounded to `integer_exp` places right of the decimal point. If `integer_exp` is negative,
  218. `numeric_exp` is rounded to |`integer_exp`| places to the left of the decimal point. If `integer_exp` is omitted,
  219. the function will perform as if `integer_exp` would be 0. The returned numeric data type is the same as the data type
  220. of `numeric_exp`.
  221. ["source","sql",subs="attributes,macros"]
  222. --------------------------------------------------
  223. include-tagged::{sql-specs}/docs.csv-spec[mathRoundWithPositiveParameter]
  224. --------------------------------------------------
  225. ["source","sql",subs="attributes,macros"]
  226. --------------------------------------------------
  227. include-tagged::{sql-specs}/docs.csv-spec[mathRoundWithNegativeParameter]
  228. --------------------------------------------------
  229. [[sql-functions-math-sign]]
  230. ===== `SIGN`
  231. .Synopsis:
  232. [source, sql]
  233. --------------------------------------------------
  234. SIGN(numeric_exp<1>)
  235. --------------------------------------------------
  236. *Input*:
  237. <1> numeric expression
  238. *Output*: [-1, 0, 1]
  239. .Description:
  240. 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.
  241. ["source","sql",subs="attributes,macros"]
  242. --------------------------------------------------
  243. include-tagged::{sql-specs}/docs.csv-spec[mathInlineSign]
  244. --------------------------------------------------
  245. [[sql-functions-math-sqrt]]
  246. ===== `SQRT`
  247. .Synopsis:
  248. [source, sql]
  249. --------------------------------------------------
  250. SQRT(numeric_exp<1>)
  251. --------------------------------------------------
  252. *Input*:
  253. <1> numeric expression
  254. *Output*: double numeric value
  255. .Description:
  256. Returns https://en.wikipedia.org/wiki/Square_root[square root] of `numeric_exp`.
  257. ["source","sql",subs="attributes,macros"]
  258. --------------------------------------------------
  259. include-tagged::{sql-specs}/docs.csv-spec[mathInlineSqrt]
  260. --------------------------------------------------
  261. [[sql-functions-math-truncate]]
  262. ===== `TRUNCATE`
  263. .Synopsis:
  264. [source, sql]
  265. ----
  266. TRUNCATE(numeric_exp<1>[, integer_exp<2>])
  267. ----
  268. *Input*:
  269. <1> numeric expression
  270. <2> integer expression; optional
  271. *Output*: numeric
  272. .Description:
  273. Returns `numeric_exp` truncated to `integer_exp` places right of the decimal point. If `integer_exp` is negative,
  274. `numeric_exp` is truncated to |`integer_exp`| places to the left of the decimal point. If `integer_exp` is omitted,
  275. the function will perform as if `integer_exp` would be 0. The returned numeric data type is the same as the data type
  276. of `numeric_exp`.
  277. ["source","sql",subs="attributes,macros"]
  278. --------------------------------------------------
  279. include-tagged::{sql-specs}/docs.csv-spec[mathTruncateWithPositiveParameter]
  280. --------------------------------------------------
  281. ["source","sql",subs="attributes,macros"]
  282. --------------------------------------------------
  283. include-tagged::{sql-specs}/docs.csv-spec[mathTruncateWithNegativeParameter]
  284. --------------------------------------------------
  285. ==== Trigonometric
  286. [[sql-functions-math-acos]]
  287. ===== `ACOS`
  288. .Synopsis:
  289. [source, sql]
  290. --------------------------------------------------
  291. ACOS(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[arccosine] of `numeric_exp` as an angle, expressed in radians.
  298. ["source","sql",subs="attributes,macros"]
  299. --------------------------------------------------
  300. include-tagged::{sql-specs}/docs.csv-spec[mathInlineAcos]
  301. --------------------------------------------------
  302. [[sql-functions-math-asin]]
  303. ===== `ASIN`
  304. .Synopsis:
  305. [source, sql]
  306. --------------------------------------------------
  307. ASIN(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[arcsine] of `numeric_exp` as an angle, expressed in radians.
  314. ["source","sql",subs="attributes,macros"]
  315. --------------------------------------------------
  316. include-tagged::{sql-specs}/docs.csv-spec[mathInlineAsin]
  317. --------------------------------------------------
  318. [[sql-functions-math-atan]]
  319. ===== `ATAN`
  320. .Synopsis:
  321. [source, sql]
  322. --------------------------------------------------
  323. ATAN(numeric_exp<1>)
  324. --------------------------------------------------
  325. *Input*:
  326. <1> numeric expression
  327. *Output*: double numeric value
  328. .Description:
  329. Returns the https://en.wikipedia.org/wiki/Inverse_trigonometric_functions[arctangent] of `numeric_exp` as an angle, expressed in radians.
  330. ["source","sql",subs="attributes,macros"]
  331. --------------------------------------------------
  332. include-tagged::{sql-specs}/docs.csv-spec[mathInlineAtan]
  333. --------------------------------------------------
  334. [[sql-functions-math-atan2]]
  335. ===== `ATAN2`
  336. .Synopsis:
  337. [source, sql]
  338. --------------------------------------------------
  339. ATAN2(ordinate<1>, abscisa<2>)
  340. --------------------------------------------------
  341. *Input*:
  342. <1> numeric expression
  343. <2> numeric expression
  344. *Output*: double numeric value
  345. .Description:
  346. Returns the https://en.wikipedia.org/wiki/Atan2[arctangent of the `ordinate` and `abscisa` coordinates] specified as an angle, expressed in radians.
  347. ["source","sql",subs="attributes,macros"]
  348. --------------------------------------------------
  349. include-tagged::{sql-specs}/docs.csv-spec[mathInlineAtan2]
  350. --------------------------------------------------
  351. [[sql-functions-math-cos]]
  352. ===== `COS`
  353. .Synopsis:
  354. [source, sql]
  355. --------------------------------------------------
  356. COS(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/Trigonometric_functions#cosine[cosine] of `numeric_exp`, where `numeric_exp` is an angle expressed in radians.
  363. ["source","sql",subs="attributes,macros"]
  364. --------------------------------------------------
  365. include-tagged::{sql-specs}/docs.csv-spec[mathInlineCosine]
  366. --------------------------------------------------
  367. [[sql-functions-math-cosh]]
  368. ===== `COSH`
  369. .Synopsis:
  370. [source, sql]
  371. --------------------------------------------------
  372. COSH(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/Hyperbolic_function[hyperbolic cosine] of `numeric_exp`.
  379. ["source","sql",subs="attributes,macros"]
  380. --------------------------------------------------
  381. include-tagged::{sql-specs}/docs.csv-spec[mathInlineCosh]
  382. --------------------------------------------------
  383. [[sql-functions-math-cot]]
  384. ===== `COT`
  385. .Synopsis:
  386. [source, sql]
  387. --------------------------------------------------
  388. COT(numeric_exp<1>)
  389. --------------------------------------------------
  390. *Input*:
  391. <1> numeric expression
  392. *Output*: double numeric value
  393. .Description:
  394. 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.
  395. ["source","sql",subs="attributes,macros"]
  396. --------------------------------------------------
  397. include-tagged::{sql-specs}/docs.csv-spec[mathInlineCotangent]
  398. --------------------------------------------------
  399. [[sql-functions-math-degrees]]
  400. ===== `DEGREES`
  401. .Synopsis:
  402. [source, sql]
  403. --------------------------------------------------
  404. DEGREES(numeric_exp<1>)
  405. --------------------------------------------------
  406. *Input*:
  407. <1> numeric expression
  408. *Output*: double numeric value
  409. .Description:
  410. Convert from https://en.wikipedia.org/wiki/Radian[radians]
  411. to https://en.wikipedia.org/wiki/Degree_(angle)[degrees].
  412. ["source","sql",subs="attributes,macros"]
  413. --------------------------------------------------
  414. include-tagged::{sql-specs}/docs.csv-spec[mathInlineDegrees]
  415. --------------------------------------------------
  416. [[sql-functions-math-radians]]
  417. ===== `RADIANS`
  418. .Synopsis:
  419. [source, sql]
  420. --------------------------------------------------
  421. RADIANS(numeric_exp<1>)
  422. --------------------------------------------------
  423. *Input*:
  424. <1> numeric expression
  425. *Output*: double numeric value
  426. .Description:
  427. Convert from https://en.wikipedia.org/wiki/Degree_(angle)[degrees]
  428. to https://en.wikipedia.org/wiki/Radian[radians].
  429. ["source","sql",subs="attributes,macros"]
  430. --------------------------------------------------
  431. include-tagged::{sql-specs}/docs.csv-spec[mathInlineRadians]
  432. --------------------------------------------------
  433. [[sql-functions-math-sin]]
  434. ===== `SIN`
  435. .Synopsis:
  436. [source, sql]
  437. --------------------------------------------------
  438. SIN(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/Trigonometric_functions#sine[sine] of `numeric_exp`, where `numeric_exp` is an angle expressed in radians.
  445. ["source","sql",subs="attributes,macros"]
  446. --------------------------------------------------
  447. include-tagged::{sql-specs}/docs.csv-spec[mathInlineSine]
  448. --------------------------------------------------
  449. [[sql-functions-math-sinh]]
  450. ===== `SINH`
  451. .Synopsis:
  452. [source, sql]
  453. --------------------------------------------------
  454. SINH(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/Hyperbolic_function[hyperbolic sine] of `numeric_exp`.
  461. ["source","sql",subs="attributes,macros"]
  462. --------------------------------------------------
  463. include-tagged::{sql-specs}/docs.csv-spec[mathInlineSinh]
  464. --------------------------------------------------
  465. [[sql-functions-math-tan]]
  466. ===== `TAN`
  467. .Synopsis:
  468. [source, sql]
  469. --------------------------------------------------
  470. TAN(numeric_exp<1>)
  471. --------------------------------------------------
  472. *Input*:
  473. <1> numeric expression
  474. *Output*: double numeric value
  475. .Description:
  476. Returns the https://en.wikipedia.org/wiki/Trigonometric_functions#tangent[tangent] of `numeric_exp`, where `numeric_exp` is an angle expressed in radians.
  477. ["source","sql",subs="attributes,macros"]
  478. --------------------------------------------------
  479. include-tagged::{sql-specs}/docs.csv-spec[mathInlineTanget]
  480. --------------------------------------------------