math.asciidoc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  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. [float]
  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:
  21. Returns the https://en.wikipedia.org/wiki/Absolute_value[absolute value] of `numeric_exp`. The return type is the same as the input type.
  22. ["source","sql",subs="attributes,macros"]
  23. --------------------------------------------------
  24. include-tagged::{sql-specs}/docs/docs.csv-spec[abs]
  25. --------------------------------------------------
  26. [[sql-functions-math-cbrt]]
  27. ==== `CBRT`
  28. .Synopsis:
  29. [source, sql]
  30. --------------------------------------------------
  31. CBRT(numeric_exp) <1>
  32. --------------------------------------------------
  33. *Input*:
  34. <1> numeric expression
  35. *Output*: double numeric value
  36. .Description:
  37. Returns the https://en.wikipedia.org/wiki/Cube_root[cube root] of `numeric_exp`.
  38. ["source","sql",subs="attributes,macros"]
  39. --------------------------------------------------
  40. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineCbrtWithNegativeValue]
  41. --------------------------------------------------
  42. [[sql-functions-math-ceil]]
  43. ==== `CEIL/CEILING`
  44. .Synopsis:
  45. [source, sql]
  46. --------------------------------------------------
  47. CEIL(numeric_exp) <1>
  48. --------------------------------------------------
  49. *Input*:
  50. <1> 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/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/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/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/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/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/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/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/docs.csv-spec[mathPINumber]
  167. --------------------------------------------------
  168. [[sql-functions-math-power]]
  169. ==== `POWER`
  170. .Synopsis:
  171. [source, sql]
  172. --------------------------------------------------
  173. POWER(
  174. numeric_exp, <1>
  175. integer_exp) <2>
  176. --------------------------------------------------
  177. *Input*:
  178. <1> numeric expression
  179. <2> integer expression
  180. *Output*: double numeric value
  181. .Description:
  182. Returns the value of `numeric_exp` to the power of `integer_exp`.
  183. ["source","sql",subs="attributes,macros"]
  184. --------------------------------------------------
  185. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlinePowerPositive]
  186. --------------------------------------------------
  187. ["source","sql",subs="attributes,macros"]
  188. --------------------------------------------------
  189. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlinePowerNegative]
  190. --------------------------------------------------
  191. [[sql-functions-math-random]]
  192. ==== `RANDOM/RAND`
  193. .Synopsis:
  194. [source, sql]
  195. --------------------------------------------------
  196. RANDOM(seed) <1>
  197. --------------------------------------------------
  198. *Input*:
  199. <1> numeric expression
  200. *Output*: double numeric value
  201. .Description:
  202. Returns a random double using the given seed.
  203. ["source","sql",subs="attributes,macros"]
  204. --------------------------------------------------
  205. include-tagged::{sql-specs}/docs/docs.csv-spec[mathRandom]
  206. --------------------------------------------------
  207. [[sql-functions-math-round]]
  208. ==== `ROUND`
  209. .Synopsis:
  210. [source, sql]
  211. ----
  212. ROUND(
  213. numeric_exp <1>
  214. [, integer_exp]) <2>
  215. ----
  216. *Input*:
  217. <1> numeric expression
  218. <2> integer expression; optional
  219. *Output*: numeric
  220. .Description:
  221. Returns `numeric_exp` rounded to `integer_exp` places right of the decimal point. If `integer_exp` is negative,
  222. `numeric_exp` is rounded to |`integer_exp`| places to the left of the decimal point. If `integer_exp` is omitted,
  223. the function will perform as if `integer_exp` would be 0. The returned numeric data type is the same as the data type
  224. of `numeric_exp`.
  225. ["source","sql",subs="attributes,macros"]
  226. --------------------------------------------------
  227. include-tagged::{sql-specs}/docs/docs.csv-spec[mathRoundWithPositiveParameter]
  228. --------------------------------------------------
  229. ["source","sql",subs="attributes,macros"]
  230. --------------------------------------------------
  231. include-tagged::{sql-specs}/docs/docs.csv-spec[mathRoundWithNegativeParameter]
  232. --------------------------------------------------
  233. [[sql-functions-math-sign]]
  234. ==== `SIGN/SIGNUM`
  235. .Synopsis:
  236. [source, sql]
  237. --------------------------------------------------
  238. SIGN(numeric_exp) <1>
  239. --------------------------------------------------
  240. *Input*:
  241. <1> numeric expression
  242. *Output*: [-1, 0, 1]
  243. .Description:
  244. 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.
  245. ["source","sql",subs="attributes,macros"]
  246. --------------------------------------------------
  247. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineSign]
  248. --------------------------------------------------
  249. [[sql-functions-math-sqrt]]
  250. ==== `SQRT`
  251. .Synopsis:
  252. [source, sql]
  253. --------------------------------------------------
  254. SQRT(numeric_exp) <1>
  255. --------------------------------------------------
  256. *Input*:
  257. <1> numeric expression
  258. *Output*: double numeric value
  259. .Description:
  260. Returns https://en.wikipedia.org/wiki/Square_root[square root] of `numeric_exp`.
  261. ["source","sql",subs="attributes,macros"]
  262. --------------------------------------------------
  263. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineSqrt]
  264. --------------------------------------------------
  265. [[sql-functions-math-truncate]]
  266. ==== `TRUNCATE`
  267. .Synopsis:
  268. [source, sql]
  269. ----
  270. TRUNCATE(
  271. numeric_exp <1>
  272. [, integer_exp]) <2>
  273. ----
  274. *Input*:
  275. <1> numeric expression
  276. <2> integer expression; optional
  277. *Output*: numeric
  278. .Description:
  279. Returns `numeric_exp` truncated to `integer_exp` places right of the decimal point. If `integer_exp` is negative,
  280. `numeric_exp` is truncated to |`integer_exp`| places to the left of the decimal point. If `integer_exp` is omitted,
  281. the function will perform as if `integer_exp` would be 0. The returned numeric data type is the same as the data type
  282. of `numeric_exp`.
  283. ["source","sql",subs="attributes,macros"]
  284. --------------------------------------------------
  285. include-tagged::{sql-specs}/docs/docs.csv-spec[mathTruncateWithPositiveParameter]
  286. --------------------------------------------------
  287. ["source","sql",subs="attributes,macros"]
  288. --------------------------------------------------
  289. include-tagged::{sql-specs}/docs/docs.csv-spec[mathTruncateWithNegativeParameter]
  290. --------------------------------------------------
  291. [[sql-functions-math-trigonometric]]
  292. [float]
  293. === Trigonometric
  294. [[sql-functions-math-acos]]
  295. ==== `ACOS`
  296. .Synopsis:
  297. [source, sql]
  298. --------------------------------------------------
  299. ACOS(numeric_exp) <1>
  300. --------------------------------------------------
  301. *Input*:
  302. <1> numeric expression
  303. *Output*: double numeric value
  304. .Description:
  305. Returns the https://en.wikipedia.org/wiki/Inverse_trigonometric_functions[arccosine] of `numeric_exp` as an angle, expressed in radians.
  306. ["source","sql",subs="attributes,macros"]
  307. --------------------------------------------------
  308. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineAcos]
  309. --------------------------------------------------
  310. [[sql-functions-math-asin]]
  311. ==== `ASIN`
  312. .Synopsis:
  313. [source, sql]
  314. --------------------------------------------------
  315. ASIN(numeric_exp) <1>
  316. --------------------------------------------------
  317. *Input*:
  318. <1> numeric expression
  319. *Output*: double numeric value
  320. .Description:
  321. Returns the https://en.wikipedia.org/wiki/Inverse_trigonometric_functions[arcsine] of `numeric_exp` as an angle, expressed in radians.
  322. ["source","sql",subs="attributes,macros"]
  323. --------------------------------------------------
  324. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineAsin]
  325. --------------------------------------------------
  326. [[sql-functions-math-atan]]
  327. ==== `ATAN`
  328. .Synopsis:
  329. [source, sql]
  330. --------------------------------------------------
  331. ATAN(numeric_exp) <1>
  332. --------------------------------------------------
  333. *Input*:
  334. <1> numeric expression
  335. *Output*: double numeric value
  336. .Description:
  337. Returns the https://en.wikipedia.org/wiki/Inverse_trigonometric_functions[arctangent] of `numeric_exp` as an angle, expressed in radians.
  338. ["source","sql",subs="attributes,macros"]
  339. --------------------------------------------------
  340. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineAtan]
  341. --------------------------------------------------
  342. [[sql-functions-math-atan2]]
  343. ==== `ATAN2`
  344. .Synopsis:
  345. [source, sql]
  346. --------------------------------------------------
  347. ATAN2(
  348. ordinate, <1>
  349. abscisa) <2>
  350. --------------------------------------------------
  351. *Input*:
  352. <1> numeric expression
  353. <2> numeric expression
  354. *Output*: double numeric value
  355. .Description:
  356. Returns the https://en.wikipedia.org/wiki/Atan2[arctangent of the `ordinate` and `abscisa` coordinates] specified as an angle, expressed in radians.
  357. ["source","sql",subs="attributes,macros"]
  358. --------------------------------------------------
  359. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineAtan2]
  360. --------------------------------------------------
  361. [[sql-functions-math-cos]]
  362. ==== `COS`
  363. .Synopsis:
  364. [source, sql]
  365. --------------------------------------------------
  366. COS(numeric_exp) <1>
  367. --------------------------------------------------
  368. *Input*:
  369. <1> numeric expression
  370. *Output*: double numeric value
  371. .Description:
  372. Returns the https://en.wikipedia.org/wiki/Trigonometric_functions#cosine[cosine] of `numeric_exp`, where `numeric_exp` is an angle expressed in radians.
  373. ["source","sql",subs="attributes,macros"]
  374. --------------------------------------------------
  375. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineCosine]
  376. --------------------------------------------------
  377. [[sql-functions-math-cosh]]
  378. ==== `COSH`
  379. .Synopsis:
  380. [source, sql]
  381. --------------------------------------------------
  382. COSH(numeric_exp) <1>
  383. --------------------------------------------------
  384. *Input*:
  385. <1> numeric expression
  386. *Output*: double numeric value
  387. .Description:
  388. Returns the https://en.wikipedia.org/wiki/Hyperbolic_function[hyperbolic cosine] of `numeric_exp`.
  389. ["source","sql",subs="attributes,macros"]
  390. --------------------------------------------------
  391. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineCosh]
  392. --------------------------------------------------
  393. [[sql-functions-math-cot]]
  394. ==== `COT`
  395. .Synopsis:
  396. [source, sql]
  397. --------------------------------------------------
  398. COT(numeric_exp) <1>
  399. --------------------------------------------------
  400. *Input*:
  401. <1> numeric expression
  402. *Output*: double numeric value
  403. .Description:
  404. 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.
  405. ["source","sql",subs="attributes,macros"]
  406. --------------------------------------------------
  407. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineCotangent]
  408. --------------------------------------------------
  409. [[sql-functions-math-degrees]]
  410. ==== `DEGREES`
  411. .Synopsis:
  412. [source, sql]
  413. --------------------------------------------------
  414. DEGREES(numeric_exp) <1>
  415. --------------------------------------------------
  416. *Input*:
  417. <1> numeric expression
  418. *Output*: double numeric value
  419. .Description:
  420. Convert from https://en.wikipedia.org/wiki/Radian[radians]
  421. to https://en.wikipedia.org/wiki/Degree_(angle)[degrees].
  422. ["source","sql",subs="attributes,macros"]
  423. --------------------------------------------------
  424. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineDegrees]
  425. --------------------------------------------------
  426. [[sql-functions-math-radians]]
  427. ==== `RADIANS`
  428. .Synopsis:
  429. [source, sql]
  430. --------------------------------------------------
  431. RADIANS(numeric_exp) <1>
  432. --------------------------------------------------
  433. *Input*:
  434. <1> numeric expression
  435. *Output*: double numeric value
  436. .Description:
  437. Convert from https://en.wikipedia.org/wiki/Degree_(angle)[degrees]
  438. to https://en.wikipedia.org/wiki/Radian[radians].
  439. ["source","sql",subs="attributes,macros"]
  440. --------------------------------------------------
  441. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineRadians]
  442. --------------------------------------------------
  443. [[sql-functions-math-sin]]
  444. ==== `SIN`
  445. .Synopsis:
  446. [source, sql]
  447. --------------------------------------------------
  448. SIN(numeric_exp) <1>
  449. --------------------------------------------------
  450. *Input*:
  451. <1> numeric expression
  452. *Output*: double numeric value
  453. .Description:
  454. Returns the https://en.wikipedia.org/wiki/Trigonometric_functions#sine[sine] of `numeric_exp`, where `numeric_exp` is an angle expressed in radians.
  455. ["source","sql",subs="attributes,macros"]
  456. --------------------------------------------------
  457. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineSine]
  458. --------------------------------------------------
  459. [[sql-functions-math-sinh]]
  460. ==== `SINH`
  461. .Synopsis:
  462. [source, sql]
  463. --------------------------------------------------
  464. SINH(numeric_exp) <1>
  465. --------------------------------------------------
  466. *Input*:
  467. <1> numeric expression
  468. *Output*: double numeric value
  469. .Description:
  470. Returns the https://en.wikipedia.org/wiki/Hyperbolic_function[hyperbolic sine] of `numeric_exp`.
  471. ["source","sql",subs="attributes,macros"]
  472. --------------------------------------------------
  473. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineSinh]
  474. --------------------------------------------------
  475. [[sql-functions-math-tan]]
  476. ==== `TAN`
  477. .Synopsis:
  478. [source, sql]
  479. --------------------------------------------------
  480. TAN(numeric_exp) <1>
  481. --------------------------------------------------
  482. *Input*:
  483. <1> numeric expression
  484. *Output*: double numeric value
  485. .Description:
  486. Returns the https://en.wikipedia.org/wiki/Trigonometric_functions#tangent[tangent] of `numeric_exp`, where `numeric_exp` is an angle expressed in radians.
  487. ["source","sql",subs="attributes,macros"]
  488. --------------------------------------------------
  489. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineTanget]
  490. --------------------------------------------------