math.asciidoc 17 KB

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