math.asciidoc 17 KB

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