math.asciidoc 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. * `ABS`
  9. https://en.wikipedia.org/wiki/Absolute_value[Absolute value], returns \[same type as input]
  10. ["source","sql",subs="attributes,callouts,macros"]
  11. --------------------------------------------------
  12. include-tagged::{sql-specs}/math.sql-spec[abs]
  13. --------------------------------------------------
  14. * `CBRT`
  15. https://en.wikipedia.org/wiki/Cube_root[Cube root], returns `double`
  16. // TODO make the example in the tests presentable
  17. * `CEIL`
  18. https://en.wikipedia.org/wiki/Floor_and_ceiling_functions[Ceiling], returns `double`
  19. * `CEILING`
  20. Same as `CEIL`
  21. // TODO make the example in the tests presentable
  22. * `E`
  23. https://en.wikipedia.org/wiki/E_%28mathematical_constant%29[Euler's number], returns `2.7182818284590452354`
  24. * https://en.wikipedia.org/wiki/Rounding#Round_half_up[Round] (`ROUND`)
  25. // TODO make the example in the tests presentable
  26. NOTE: This rounds "half up" meaning that `ROUND(-1.5)` results in `-1`.
  27. * https://en.wikipedia.org/wiki/Floor_and_ceiling_functions[Floor] (`FLOOR`)
  28. // TODO make the example in the tests presentable
  29. * https://en.wikipedia.org/wiki/Natural_logarithm[Natural logarithm] (`LOG`)
  30. ["source","sql",subs="attributes,callouts,macros"]
  31. --------------------------------------------------
  32. include-tagged::{sql-specs}/math.sql-spec[log]
  33. --------------------------------------------------
  34. * https://en.wikipedia.org/wiki/Logarithm[Logarithm] base 10 (`LOG10`)
  35. ["source","sql",subs="attributes,callouts,macros"]
  36. --------------------------------------------------
  37. include-tagged::{sql-specs}/math.sql-spec[log10]
  38. --------------------------------------------------
  39. * https://en.wikipedia.org/wiki/Square_root[Square root] (`SQRT`)
  40. ["source","sql",subs="attributes,callouts,macros"]
  41. --------------------------------------------------
  42. include-tagged::{sql-specs}/math.sql-spec[sqrt]
  43. --------------------------------------------------
  44. * https://en.wikipedia.org/wiki/Exponential_function[e^x^] (`EXP`)
  45. ["source","sql",subs="attributes,callouts,macros"]
  46. --------------------------------------------------
  47. include-tagged::{sql-specs}/math.sql-spec[exp]
  48. --------------------------------------------------
  49. * https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#expm1-double-[e^x^ - 1] (`EXPM1`)
  50. ["source","sql",subs="attributes,callouts,macros"]
  51. --------------------------------------------------
  52. include-tagged::{sql-specs}/math.sql-spec[expm1]
  53. --------------------------------------------------
  54. ==== Trigonometric
  55. * Convert from https://en.wikipedia.org/wiki/Radian[radians]
  56. to https://en.wikipedia.org/wiki/Degree_(angle)[degrees] (`DEGREES`)
  57. ["source","sql",subs="attributes,callouts,macros"]
  58. --------------------------------------------------
  59. include-tagged::{sql-specs}/math.sql-spec[degrees]
  60. --------------------------------------------------
  61. * Convert from https://en.wikipedia.org/wiki/Degree_(angle)[degrees]
  62. to https://en.wikipedia.org/wiki/Radian[radians] (`RADIANS`)
  63. ["source","sql",subs="attributes,callouts,macros"]
  64. --------------------------------------------------
  65. include-tagged::{sql-specs}/math.sql-spec[degrees]
  66. --------------------------------------------------
  67. * https://en.wikipedia.org/wiki/Trigonometric_functions#sine[Sine] (`SIN`)
  68. ["source","sql",subs="attributes,callouts,macros"]
  69. --------------------------------------------------
  70. include-tagged::{sql-specs}/math.sql-spec[sin]
  71. --------------------------------------------------
  72. * https://en.wikipedia.org/wiki/Trigonometric_functions#cosine[Cosine] (`COS`)
  73. ["source","sql",subs="attributes,callouts,macros"]
  74. --------------------------------------------------
  75. include-tagged::{sql-specs}/math.sql-spec[cos]
  76. --------------------------------------------------
  77. * https://en.wikipedia.org/wiki/Trigonometric_functions#tangent[Tangent] (`TAN`)
  78. ["source","sql",subs="attributes,callouts,macros"]
  79. --------------------------------------------------
  80. include-tagged::{sql-specs}/math.sql-spec[tan]
  81. --------------------------------------------------
  82. * https://en.wikipedia.org/wiki/Inverse_trigonometric_functions[Arc sine] (`ASIN`)
  83. ["source","sql",subs="attributes,callouts,macros"]
  84. --------------------------------------------------
  85. include-tagged::{sql-specs}/math.sql-spec[asin]
  86. --------------------------------------------------
  87. * https://en.wikipedia.org/wiki/Inverse_trigonometric_functions[Arc cosine] (`ACOS`)
  88. ["source","sql",subs="attributes,callouts,macros"]
  89. --------------------------------------------------
  90. include-tagged::{sql-specs}/math.sql-spec[acos]
  91. --------------------------------------------------
  92. * https://en.wikipedia.org/wiki/Inverse_trigonometric_functions[Arc tangent] (`ATAN`)
  93. ["source","sql",subs="attributes,callouts,macros"]
  94. --------------------------------------------------
  95. include-tagged::{sql-specs}/math.sql-spec[atan]
  96. --------------------------------------------------
  97. * https://en.wikipedia.org/wiki/Hyperbolic_function[Hyperbolic sine] (`SINH`)
  98. ["source","sql",subs="attributes,callouts,macros"]
  99. --------------------------------------------------
  100. include-tagged::{sql-specs}/math.sql-spec[sinh]
  101. --------------------------------------------------
  102. * https://en.wikipedia.org/wiki/Hyperbolic_function[Hyperbolic cosine] (`COSH`)
  103. ["source","sql",subs="attributes,callouts,macros"]
  104. --------------------------------------------------
  105. include-tagged::{sql-specs}/math.sql-spec[cosh]
  106. --------------------------------------------------