math.asciidoc 17 KB

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