math.asciidoc 18 KB

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