complex.d.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. type AValue =
  2. | Complex
  3. | { im: number; re: number }
  4. | { abs: number; arg: number }
  5. | { r: number; phi: number }
  6. | [number, number]
  7. | string
  8. | number
  9. | null
  10. | undefined;
  11. type BValue = number | undefined;
  12. export function Complex(a: AValue, b?: BValue): Complex;
  13. export default Complex;
  14. /**
  15. *
  16. * This class allows the manipulation of complex numbers.
  17. * You can pass a complex number in different formats. Either as object, double, string or two integer parameters.
  18. *
  19. * Object form
  20. * { re: <real>, im: <imaginary> }
  21. * { arg: <angle>, abs: <radius> }
  22. * { phi: <angle>, r: <radius> }
  23. *
  24. * Array / Vector form
  25. * [ real, imaginary ]
  26. *
  27. * Double form
  28. * 99.3 - Single double value
  29. *
  30. * String form
  31. * '23.1337' - Simple real number
  32. * '15+3i' - a simple complex number
  33. * '3-i' - a simple complex number
  34. *
  35. * Example:
  36. *
  37. * var c = new Complex('99.3+8i');
  38. * c.mul({r: 3, i: 9}).div(4.9).sub(3, 2);
  39. *
  40. */
  41. export class Complex {
  42. re: number;
  43. im: number;
  44. constructor(a: AValue, b?: BValue);
  45. /**
  46. * Calculates the sign of a complex number, which is a normalized complex
  47. *
  48. */
  49. sign(): Complex;
  50. /**
  51. * Adds two complex numbers
  52. *
  53. */
  54. add(a: AValue, b?: BValue): Complex;
  55. /**
  56. * Subtracts two complex numbers
  57. *
  58. */
  59. sub(a: AValue, b?: BValue): Complex;
  60. /**
  61. * Multiplies two complex numbers
  62. *
  63. */
  64. mul(a: AValue, b?: BValue): Complex;
  65. /**
  66. * Divides two complex numbers
  67. *
  68. */
  69. div(a: AValue, b?: BValue): Complex;
  70. /**
  71. * Calculate the power of two complex numbers
  72. *
  73. */
  74. pow(a: AValue, b?: BValue): Complex;
  75. /**
  76. * Calculate the complex square root
  77. *
  78. */
  79. sqrt(): Complex;
  80. /**
  81. * Calculate the complex exponent
  82. *
  83. */
  84. exp(): Complex;
  85. /**
  86. * Calculate the complex exponent and subtracts one.
  87. *
  88. * This may be more accurate than `Complex(x).exp().sub(1)` if
  89. * `x` is small.
  90. *
  91. */
  92. expm1(): Complex;
  93. /**
  94. * Calculate the natural log
  95. *
  96. */
  97. log(): Complex;
  98. /**
  99. * Calculate the magnitude of the complex number
  100. *
  101. */
  102. abs(): number;
  103. /**
  104. * Calculate the angle of the complex number
  105. *
  106. */
  107. arg(): number;
  108. /**
  109. * Calculate the sine of the complex number
  110. *
  111. */
  112. sin(): Complex;
  113. /**
  114. * Calculate the cosine
  115. *
  116. */
  117. cos(): Complex;
  118. /**
  119. * Calculate the tangent
  120. *
  121. */
  122. tan(): Complex;
  123. /**
  124. * Calculate the cotangent
  125. *
  126. */
  127. cot(): Complex;
  128. /**
  129. * Calculate the secant
  130. *
  131. */
  132. sec(): Complex;
  133. /**
  134. * Calculate the cosecans
  135. *
  136. */
  137. csc(): Complex;
  138. /**
  139. * Calculate the complex arcus sinus
  140. *
  141. */
  142. asin(): Complex;
  143. /**
  144. * Calculate the complex arcus cosinus
  145. *
  146. */
  147. acos(): Complex;
  148. /**
  149. * Calculate the complex arcus tangent
  150. *
  151. */
  152. atan(): Complex;
  153. /**
  154. * Calculate the complex arcus cotangent
  155. *
  156. */
  157. acot(): Complex;
  158. /**
  159. * Calculate the complex arcus secant
  160. *
  161. */
  162. asec(): Complex;
  163. /**
  164. * Calculate the complex arcus cosecans
  165. *
  166. */
  167. acsc(): Complex;
  168. /**
  169. * Calculate the complex sinh
  170. *
  171. */
  172. sinh(): Complex;
  173. /**
  174. * Calculate the complex cosh
  175. *
  176. */
  177. cosh(): Complex;
  178. /**
  179. * Calculate the complex tanh
  180. *
  181. */
  182. tanh(): Complex;
  183. /**
  184. * Calculate the complex coth
  185. *
  186. */
  187. coth(): Complex;
  188. /**
  189. * Calculate the complex coth
  190. *
  191. */
  192. csch(): Complex;
  193. /**
  194. * Calculate the complex sech
  195. *
  196. */
  197. sech(): Complex;
  198. /**
  199. * Calculate the complex asinh
  200. *
  201. */
  202. asinh(): Complex;
  203. /**
  204. * Calculate the complex acosh
  205. *
  206. */
  207. acosh(): Complex;
  208. /**
  209. * Calculate the complex atanh
  210. *
  211. */
  212. atanh(): Complex;
  213. /**
  214. * Calculate the complex acoth
  215. *
  216. */
  217. acoth(): Complex;
  218. /**
  219. * Calculate the complex acsch
  220. *
  221. */
  222. acsch(): Complex;
  223. /**
  224. * Calculate the complex asech
  225. *
  226. */
  227. asech(): Complex;
  228. /**
  229. * Calculate the complex inverse 1/z
  230. *
  231. */
  232. inverse(): Complex;
  233. /**
  234. * Returns the complex conjugate
  235. *
  236. */
  237. conjugate(): Complex;
  238. /**
  239. * Gets the negated complex number
  240. *
  241. */
  242. neg(): Complex;
  243. /**
  244. * Ceils the actual complex number
  245. *
  246. */
  247. ceil(places: number): Complex;
  248. /**
  249. * Floors the actual complex number
  250. *
  251. */
  252. floor(places: number): Complex;
  253. /**
  254. * Ceils the actual complex number
  255. *
  256. */
  257. round(places: number): Complex;
  258. /**
  259. * Compares two complex numbers
  260. *
  261. * **Note:** new Complex(Infinity).equals(Infinity) === false
  262. *
  263. */
  264. equals(a: AValue, b?: BValue): boolean;
  265. /**
  266. * Clones the actual object
  267. *
  268. */
  269. clone(): Complex;
  270. /**
  271. * Gets a string of the actual complex number
  272. *
  273. */
  274. toString(): string;
  275. /**
  276. * Returns the actual number as a vector
  277. *
  278. */
  279. toVector(): number[];
  280. /**
  281. * Returns the actual real value of the current object
  282. *
  283. * @returns {number|null}
  284. */
  285. valueOf(): number | null;
  286. /**
  287. * Determines whether a complex number is not on the Riemann sphere.
  288. *
  289. */
  290. isNaN(): boolean;
  291. /**
  292. * Determines whether or not a complex number is at the zero pole of the
  293. * Riemann sphere.
  294. *
  295. */
  296. isZero(): boolean;
  297. /**
  298. * Determines whether a complex number is not at the infinity pole of the
  299. * Riemann sphere.
  300. *
  301. */
  302. isFinite(): boolean;
  303. /**
  304. * Determines whether or not a complex number is at the infinity pole of the
  305. * Riemann sphere.
  306. *
  307. */
  308. isInfinite(): boolean;
  309. static ZERO: Complex;
  310. static ONE: Complex;
  311. static I: Complex;
  312. static PI: Complex;
  313. static E: Complex;
  314. static INFINITY: Complex;
  315. static NAN: Complex;
  316. static EPSILON: number;
  317. }