KOffice – TDE office suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
5.4KB

  1. /* This file is part of the KDE project
  2. Copyright (C) 1998-2002 The KSpread Team
  3. www.koffice.org/kspread
  4. Copyright (C) 2005 Tomas Mecir <mecirt@gmail.com>
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public
  7. License as published by the Free Software Foundation; either
  8. version 2 of the License.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Library General Public License for more details.
  13. You should have received a copy of the GNU Library General Public License
  14. along with this library; see the file COPYING.LIB. If not, write to
  15. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16. * Boston, MA 02110-1301, USA.
  17. */
  18. // built-in trigonometric functions
  19. #include "functions.h"
  20. #include "valuecalc.h"
  21. using namespace KSpread;
  22. // prototypes (sort alphabetically)
  23. Value func_acos (valVector args, ValueCalc *calc, FuncExtra *);
  24. Value func_acosh (valVector args, ValueCalc *calc, FuncExtra *);
  25. Value func_acot (valVector args, ValueCalc *calc, FuncExtra *);
  26. Value func_asinh (valVector args, ValueCalc *calc, FuncExtra *);
  27. Value func_asin (valVector args, ValueCalc *calc, FuncExtra *);
  28. Value func_atan (valVector args, ValueCalc *calc, FuncExtra *);
  29. Value func_atan2 (valVector args, ValueCalc *calc, FuncExtra *);
  30. Value func_atanh (valVector args, ValueCalc *calc, FuncExtra *);
  31. Value func_cos (valVector args, ValueCalc *calc, FuncExtra *);
  32. Value func_cosh (valVector args, ValueCalc *calc, FuncExtra *);
  33. Value func_degrees (valVector args, ValueCalc *calc, FuncExtra *);
  34. Value func_radians (valVector args, ValueCalc *calc, FuncExtra *);
  35. Value func_sin (valVector args, ValueCalc *calc, FuncExtra *);
  36. Value func_sinh (valVector args, ValueCalc *calc, FuncExtra *);
  37. Value func_tan (valVector args, ValueCalc *calc, FuncExtra *);
  38. Value func_tanh (valVector args, ValueCalc *calc, FuncExtra *);
  39. Value func_pi (valVector args, ValueCalc *calc, FuncExtra *);
  40. // registers all trigonometric functions
  41. void RegisterTrigFunctions()
  42. {
  43. FunctionRepository* repo = FunctionRepository::self();
  44. Function *f;
  45. f = new Function ("ACOS", func_acos);
  46. repo->add (f);
  47. f = new Function ("ACOSH", func_acosh);
  48. repo->add (f);
  49. f = new Function ("ACOT", func_acot);
  50. repo->add (f);
  51. f = new Function ("ASIN", func_asin);
  52. repo->add (f);
  53. f = new Function ("ASINH", func_asinh);
  54. repo->add (f);
  55. f = new Function ("ATAN", func_atan);
  56. repo->add (f);
  57. f = new Function ("ATAN2", func_atan2);
  58. f->setParamCount (2);
  59. repo->add (f);
  60. f = new Function ("ATANH", func_atanh);
  61. repo->add (f);
  62. f = new Function ("COS", func_cos);
  63. repo->add (f);
  64. f = new Function ("COSH", func_cosh);
  65. repo->add (f);
  66. f = new Function ("DEGREES",func_degrees);
  67. repo->add (f);
  68. f = new Function ("RADIANS",func_radians);
  69. repo->add (f);
  70. f = new Function ("SIN", func_sin);
  71. repo->add (f);
  72. f = new Function ("SINH", func_sinh);
  73. repo->add (f);
  74. f = new Function ("TAN", func_tan);
  75. repo->add (f);
  76. f = new Function ("TANH", func_tanh);
  77. repo->add (f);
  78. f = new Function ("PI", func_pi);
  79. f->setParamCount (0);
  80. repo->add (f);
  81. }
  82. // Function: sin
  83. Value func_sin (valVector args, ValueCalc *calc, FuncExtra *)
  84. {
  85. return calc->sin (args[0]);
  86. }
  87. // Function: cos
  88. Value func_cos (valVector args, ValueCalc *calc, FuncExtra *)
  89. {
  90. return calc->cos (args[0]);
  91. }
  92. // Function: tan
  93. Value func_tan (valVector args, ValueCalc *calc, FuncExtra *)
  94. {
  95. return calc->tg (args[0]);
  96. }
  97. // Function: atan
  98. Value func_atan (valVector args, ValueCalc *calc, FuncExtra *)
  99. {
  100. return calc->atg (args[0]);
  101. }
  102. // Function: asin
  103. Value func_asin (valVector args, ValueCalc *calc, FuncExtra *)
  104. {
  105. return calc->asin (args[0]);
  106. }
  107. // Function: acos
  108. Value func_acos (valVector args, ValueCalc *calc, FuncExtra *)
  109. {
  110. return calc->acos (args[0]);
  111. }
  112. Value func_acot (valVector args, ValueCalc *calc, FuncExtra *)
  113. {
  114. // PI/2 - atg (val)
  115. return calc->sub (calc->div (calc->pi(), 2), calc->atg (args[0]));
  116. }
  117. // Function: asinh
  118. Value func_asinh (valVector args, ValueCalc *calc, FuncExtra *)
  119. {
  120. return calc->asinh (args[0]);
  121. }
  122. // Function: acosh
  123. Value func_acosh (valVector args, ValueCalc *calc, FuncExtra *)
  124. {
  125. return calc->acosh (args[0]);
  126. }
  127. // Function: atanh
  128. Value func_atanh (valVector args, ValueCalc *calc, FuncExtra *)
  129. {
  130. return calc->atgh (args[0]);
  131. }
  132. // Function: tanh
  133. Value func_tanh (valVector args, ValueCalc *calc, FuncExtra *)
  134. {
  135. return calc->tgh (args[0]);
  136. }
  137. // Function: sinh
  138. Value func_sinh (valVector args, ValueCalc *calc, FuncExtra *)
  139. {
  140. return calc->sinh (args[0]);
  141. }
  142. // Function: cosh
  143. Value func_cosh (valVector args, ValueCalc *calc, FuncExtra *)
  144. {
  145. return calc->cosh (args[0]);
  146. }
  147. // Function: DEGREES
  148. Value func_degrees (valVector args, ValueCalc *calc, FuncExtra *)
  149. {
  150. // val * 180 / pi
  151. return calc->div (calc->mul (args[0], 180.0), calc->pi());
  152. }
  153. // Function: RADIANS
  154. Value func_radians (valVector args, ValueCalc *calc, FuncExtra *)
  155. {
  156. // val * pi / 180
  157. return calc->mul (calc->div (args[0], 180.0), calc->pi());
  158. }
  159. // Function: PI
  160. Value func_pi (valVector, ValueCalc *calc, FuncExtra *)
  161. {
  162. return calc->pi();
  163. }
  164. // Function: atan2
  165. Value func_atan2 (valVector args, ValueCalc *calc, FuncExtra *)
  166. {
  167. return calc->atan2 (args[1], args[0]);
  168. }