functions.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. * Copyright (c) 2017-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. * @author Panagiotis Tourlas <panagiot_tourlov@hotmail.com>
  6. *
  7. * Adapted from MolQL project
  8. */
  9. import { MolScriptBuilder } from '../../../mol-script/language/builder';
  10. const B = MolScriptBuilder;
  11. import { FunctionDict } from '../types';
  12. export const functions: FunctionDict = {
  13. 'sqr': {
  14. '@desc': 'square of x',
  15. '@examples': ['sqr(2)'],
  16. map: x => B.core.math.pow([x, 2]),
  17. },
  18. 'sqrt': {
  19. '@desc': 'square root of x',
  20. '@examples': ['sqrt(2)'],
  21. map: x => B.core.math.sqrt([x]),
  22. },
  23. 'abs': {
  24. '@desc': 'absolute value of x',
  25. '@examples': ['abs(2)'],
  26. map: x => B.core.math.abs([x]),
  27. },
  28. 'floor': {
  29. '@desc': 'largest integer not greater than x',
  30. '@examples': ['floor(2)'],
  31. map: x => B.core.math.floor([x]),
  32. },
  33. 'ceil': {
  34. '@desc': 'smallest integer not less than x',
  35. '@examples': ['ceil(2)'],
  36. map: x => B.core.math.ceil([x]),
  37. },
  38. 'sin': {
  39. '@desc': 'sine of x',
  40. '@examples': ['sin(2)'],
  41. map: x => B.core.math.sin([x]),
  42. },
  43. 'cos': {
  44. '@desc': 'cosine of x',
  45. '@examples': ['cos(2)'],
  46. map: x => B.core.math.cos([x]),
  47. },
  48. 'tan': {
  49. '@desc': 'tangent of x',
  50. '@examples': ['tan(2)'],
  51. map: x => B.core.math.tan([x]),
  52. },
  53. 'atan': {
  54. '@desc': 'arctangent of x',
  55. '@examples': ['atan(2)'],
  56. map: x => B.core.math.atan([x]),
  57. },
  58. 'asin': {
  59. '@desc': 'arcsin of x',
  60. '@examples': ['asin(2)'],
  61. map: x => B.core.math.asin([x]),
  62. },
  63. 'acos': {
  64. '@desc': 'arccos of x',
  65. '@examples': ['acos(2)'],
  66. map: x => B.core.math.acos([x]),
  67. },
  68. 'sinh': {
  69. '@desc': 'hyperbolic sine of x',
  70. '@examples': ['sinh(2)'],
  71. map: x => B.core.math.sinh([x]),
  72. },
  73. 'cosh': {
  74. '@desc': 'hyperbolic cosine of x',
  75. '@examples': ['cosh(2)'],
  76. map: x => B.core.math.cosh([x]),
  77. },
  78. 'tanh': {
  79. '@desc': 'hyperbolic tangent of x',
  80. '@examples': ['tanh(2)'],
  81. map: x => B.core.math.tanh([x]),
  82. },
  83. 'exp': {
  84. '@desc': 'e to the power x',
  85. '@examples': ['exp(2)'],
  86. map: x => B.core.math.exp([x]),
  87. },
  88. 'log': {
  89. '@desc': 'natural log of x',
  90. '@examples': ['log(2)'],
  91. map: x => B.core.math.log([x]),
  92. },
  93. 'log10': {
  94. '@desc': 'log base 10 of x',
  95. '@examples': ['log10(2)'],
  96. map: x => B.core.math.log10([x]),
  97. }
  98. };