pimath 0.0.128 → 0.0.129

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/dist/main.d.ts +39 -0
  2. package/dist/maths/algebra/equation.d.ts +120 -0
  3. package/dist/maths/algebra/linearSystem.d.ts +40 -0
  4. package/dist/maths/algebra/logicalset.d.ts +28 -0
  5. package/dist/maths/algebra/monom.d.ts +207 -0
  6. package/dist/maths/algebra/polynom.d.ts +155 -0
  7. package/dist/maths/algebra/rational.d.ts +44 -0
  8. package/dist/maths/algebra/study/rationalStudy.d.ts +14 -0
  9. package/dist/maths/algebra/study.d.ts +140 -0
  10. package/dist/maths/coefficients/fraction.d.ts +90 -0
  11. package/dist/maths/coefficients/nthRoot.d.ts +23 -0
  12. package/dist/maths/geometry/circle.d.ts +46 -0
  13. package/dist/maths/geometry/line.d.ts +102 -0
  14. package/dist/maths/geometry/point.d.ts +36 -0
  15. package/dist/maths/geometry/triangle.d.ts +92 -0
  16. package/dist/maths/geometry/vector.d.ts +38 -0
  17. package/dist/maths/numeric.d.ts +28 -0
  18. package/dist/maths/numexp.d.ts +19 -0
  19. package/dist/maths/randomization/random.d.ts +26 -0
  20. package/dist/maths/randomization/randomCore.d.ts +7 -0
  21. package/dist/maths/randomization/rndFraction.d.ts +13 -0
  22. package/dist/maths/randomization/rndGeometryCircle.d.ts +13 -0
  23. package/dist/maths/randomization/rndGeometryLine.d.ts +13 -0
  24. package/dist/maths/randomization/rndGeometryPoint.d.ts +13 -0
  25. package/dist/maths/randomization/rndHelpers.d.ts +23 -0
  26. package/dist/maths/randomization/rndMonom.d.ts +13 -0
  27. package/dist/maths/randomization/rndPolynom.d.ts +14 -0
  28. package/dist/maths/randomization/rndTypes.d.ts +40 -0
  29. package/dist/maths/shutingyard.d.ts +59 -0
  30. package/dist/pimath.js +85 -85
  31. package/package.json +10 -12
  32. package/.eslintrc.js +0 -24
  33. package/.idea/$CACHE_FILE$ +0 -6
  34. package/.idea/PI.iml +0 -14
  35. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  36. package/.idea/inspectionProfiles/Project_Default.xml +0 -6
  37. package/.idea/jsLibraryMappings.xml +0 -6
  38. package/.idea/misc.xml +0 -6
  39. package/.idea/modules.xml +0 -8
  40. package/.idea/php.xml +0 -19
  41. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_07_11_2023_08_30_[Default_Changelist]/shelved.patch +0 -192
  42. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_07_11_2023_08_30_[Default_Changelist]1/shelved.patch +0 -0
  43. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_07_11_2023_08_30__Default_Changelist_.xml +0 -4
  44. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_10_43_[Default_Changelist]/shelved.patch +0 -2404
  45. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_10_43__Default_Changelist_.xml +0 -4
  46. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_11_01_[Default_Changelist]/shelved.patch +0 -1362
  47. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_11_01__Default_Changelist_.xml +0 -4
  48. package/.idea/shelf/Uncommitted_changes_before_Update_at_24_07_2023_15_31_[Default_Changelist]/shelved.patch +0 -90
  49. package/.idea/shelf/Uncommitted_changes_before_Update_at_24_07_2023_15_31__Default_Changelist_.xml +0 -4
  50. package/.idea/vcs.xml +0 -6
  51. package/dist/demo/exercises.html +0 -283
  52. package/dist/demo/matrices.html +0 -39
  53. package/dist/demo/playground.html +0 -20
  54. package/dist/demo.css +0 -3
  55. package/dist/pimath.umd.cjs +0 -15
  56. package/docs/.nojekyll +0 -1
  57. package/docs/assets/highlight.css +0 -78
  58. package/docs/assets/main.js +0 -59
  59. package/docs/assets/navigation.js +0 -1
  60. package/docs/assets/search.js +0 -1
  61. package/docs/assets/style.css +0 -1383
  62. package/docs/classes/Logicalset.Logicalset.html +0 -217
  63. package/docs/classes/Polynom.Rational.html +0 -397
  64. package/docs/classes/Vector-1.Vector.html +0 -490
  65. package/docs/classes/Vector.Point.html +0 -337
  66. package/docs/classes/algebra_equation.Equation.html +0 -790
  67. package/docs/classes/algebra_linearSystem.LinearSystem.html +0 -404
  68. package/docs/classes/algebra_monom.Monom.html +0 -962
  69. package/docs/classes/algebra_polynom.Polynom.html +0 -1275
  70. package/docs/classes/coefficients_fraction.Fraction.html +0 -934
  71. package/docs/classes/geometry_circle.Circle.html +0 -472
  72. package/docs/classes/geometry_line.Line.html +0 -774
  73. package/docs/classes/geometry_triangle.Triangle.html +0 -429
  74. package/docs/classes/numeric.Numeric.html +0 -265
  75. package/docs/classes/shutingyard.Shutingyard.html +0 -250
  76. package/docs/enums/algebra_equation.PARTICULAR_SOLUTION.html +0 -83
  77. package/docs/enums/geometry_line.LinePropriety.html +0 -97
  78. package/docs/enums/shutingyard.ShutingyardMode.html +0 -97
  79. package/docs/enums/shutingyard.ShutingyardType.html +0 -111
  80. package/docs/index.html +0 -63
  81. package/docs/interfaces/algebra_equation.ISolution.html +0 -105
  82. package/docs/interfaces/algebra_polynom.IEuclidian.html +0 -87
  83. package/docs/interfaces/geometry_triangle.remarquableLines.html +0 -163
  84. package/docs/modules/Logicalset.html +0 -65
  85. package/docs/modules/Polynom.html +0 -65
  86. package/docs/modules/Vector-1.html +0 -65
  87. package/docs/modules/Vector.html +0 -65
  88. package/docs/modules/algebra_equation.html +0 -69
  89. package/docs/modules/algebra_linearSystem.html +0 -61
  90. package/docs/modules/algebra_monom.html +0 -65
  91. package/docs/modules/algebra_polynom.html +0 -69
  92. package/docs/modules/coefficients_fraction.html +0 -65
  93. package/docs/modules/geometry_circle.html +0 -61
  94. package/docs/modules/geometry_line.html +0 -65
  95. package/docs/modules/geometry_triangle.html +0 -65
  96. package/docs/modules/numeric.html +0 -61
  97. package/docs/modules/shutingyard.html +0 -75
  98. package/docs/types/algebra_monom.literalType.html +0 -61
  99. package/docs/types/algebra_polynom.PolynomParsingType.html +0 -56
  100. package/docs/types/coefficients_fraction.FractionParsingType.html +0 -56
  101. package/docs/types/shutingyard.Token.html +0 -63
  102. package/docs/types/shutingyard.tokenType.html +0 -68
  103. package/docs/variables/shutingyard.tokenConstant.html +0 -61
  104. package/index.html +0 -15
  105. package/public/demo/exercises.html +0 -283
  106. package/public/demo/matrices.html +0 -39
  107. package/public/demo/playground.html +0 -20
  108. package/public/demo.css +0 -3
  109. package/src/demo/exercises.ts +0 -0
  110. package/src/demo/matrices.ts +0 -61
  111. package/src/demo/playground.ts +0 -153
  112. package/src/main.ts +0 -42
  113. package/src/maths/algebra/equation.ts +0 -897
  114. package/src/maths/algebra/linearSystem.ts +0 -370
  115. package/src/maths/algebra/logicalset.ts +0 -183
  116. package/src/maths/algebra/monom.ts +0 -1028
  117. package/src/maths/algebra/polynom.ts +0 -1537
  118. package/src/maths/algebra/rational.ts +0 -244
  119. package/src/maths/algebra/study/rationalStudy.ts +0 -287
  120. package/src/maths/algebra/study.ts +0 -506
  121. package/src/maths/coefficients/fraction.ts +0 -593
  122. package/src/maths/coefficients/nthRoot.ts +0 -148
  123. package/src/maths/geometry/circle.ts +0 -382
  124. package/src/maths/geometry/line.ts +0 -604
  125. package/src/maths/geometry/point.ts +0 -215
  126. package/src/maths/geometry/triangle.ts +0 -368
  127. package/src/maths/geometry/vector.ts +0 -242
  128. package/src/maths/numeric.ts +0 -162
  129. package/src/maths/numexp.ts +0 -184
  130. package/src/maths/randomization/random.ts +0 -80
  131. package/src/maths/randomization/randomCore.ts +0 -19
  132. package/src/maths/randomization/rndFraction.ts +0 -47
  133. package/src/maths/randomization/rndGeometryCircle.ts +0 -50
  134. package/src/maths/randomization/rndGeometryLine.ts +0 -53
  135. package/src/maths/randomization/rndGeometryPoint.ts +0 -69
  136. package/src/maths/randomization/rndHelpers.ts +0 -107
  137. package/src/maths/randomization/rndMonom.ts +0 -57
  138. package/src/maths/randomization/rndPolynom.ts +0 -90
  139. package/src/maths/randomization/rndTypes.ts +0 -43
  140. package/src/maths/shutingyard.ts +0 -496
  141. package/tests/algebra/equation.test.ts +0 -64
  142. package/tests/algebra/linear.test.ts +0 -58
  143. package/tests/algebra/monom.test.ts +0 -78
  144. package/tests/algebra/polynom.test.ts +0 -343
  145. package/tests/algebra/rationnal.test.ts +0 -64
  146. package/tests/algebra/study.test.ts +0 -48
  147. package/tests/coefficients/fraction.test.ts +0 -131
  148. package/tests/custom.test.ts +0 -33
  149. package/tests/geometry/circle.test.ts +0 -404
  150. package/tests/geometry/line.test.ts +0 -36
  151. package/tests/numeric.test.ts +0 -43
  152. package/tests/numexp.test.ts +0 -89
  153. package/tests/shutingyard.test.ts +0 -58
  154. package/tsconfig.json +0 -52
  155. package/tsconfig.testing.json +0 -28
  156. package/typedoc.katex.js +0 -11
  157. package/vite.config.js +0 -23
  158. package/webpack-production-min.config.js +0 -26
  159. package/webpack-production.config.js +0 -26
  160. package/webpack.config.js +0 -26
@@ -1,593 +0,0 @@
1
- import {Numeric} from "../numeric";
2
-
3
- export type FractionParsingType = number | string | Fraction
4
-
5
- /**
6
- * The fraction class make possible to handle
7
- * TODO: Write the documentation correctly.
8
- * \\(\frac{a}{b}\\) or \\[\frac{a}{b}\\] values.
9
- */
10
- export class Fraction {
11
- private _denominator: number;
12
- private _numerator: number;
13
-
14
- constructor(value?: unknown, denominatorOrPeriodic?: number) {
15
- this._numerator = 1;
16
- this._denominator = 1;
17
-
18
- if (value !== undefined) {
19
- this.parse(value, denominatorOrPeriodic);
20
- }
21
-
22
- return this;
23
- }
24
-
25
- // ------------------------------------------
26
- // Getter and setter
27
- // ------------------------------------------
28
-
29
- get numerator(): number {
30
- return this._numerator;
31
- }
32
-
33
- set numerator(value: number) {
34
- this._numerator = value;
35
- }
36
-
37
- get denominator(): number {
38
- return this._denominator;
39
- }
40
-
41
- set denominator(value: number) {
42
- this._denominator = value;
43
- }
44
-
45
- get value(): number {
46
- return this._numerator / this._denominator;
47
- }
48
-
49
- // Display getter
50
- get tex(): string {
51
- if (this.isInfinity()) {
52
- return `${this.sign() === 1 ? '+' : '-'}\\infty`
53
- }
54
-
55
- if (this.isExact()) {
56
- if (this._denominator === 1) {
57
- return `${this._numerator}`;
58
- } else if (this._numerator < 0) {
59
- return `-\\frac{ ${-this._numerator} }{ ${this._denominator} }`;
60
- } else {
61
- return `\\frac{ ${this._numerator} }{ ${this._denominator} }`;
62
- }
63
- } else {
64
- return this.value.toFixed(3)
65
- }
66
- }
67
-
68
- get texWithSign():string {
69
- return this.isPositive() ? `+${this.tex}` : this.tex;
70
- }
71
-
72
- get display(): string {
73
- if (this.isExact()) {
74
- if (this._denominator === 1) {
75
- return `${this._numerator}`;
76
- } else {
77
- return `${this._numerator}/${this._denominator}`;
78
- }
79
- } else {
80
- return this.value.toFixed(3)
81
- }
82
- }
83
-
84
- // Helper function to display fractions
85
- get frac(): string {
86
- return this.tex;
87
- }
88
-
89
- get dfrac(): string {
90
- return this.tex.replace('\\frac', '\\dfrac');
91
- }
92
-
93
- get tfrac(): string {
94
- return this.tex.replace('\\frac', '\\tfrac')
95
- }
96
-
97
- static max = (...fractions: (Fraction | number)[]): Fraction => {
98
- let M = new Fraction(fractions[0])
99
-
100
- for (let m of fractions) {
101
- let compare = new Fraction(m)
102
- if (compare.greater(M)) {
103
- M = compare.clone()
104
- }
105
- }
106
-
107
- return M
108
- }
109
-
110
- static min = (...fractions: (Fraction | number)[]): Fraction => {
111
- let M = new Fraction(fractions[0])
112
-
113
- for (let m of fractions) {
114
- let compare = new Fraction(m)
115
- if (compare.lesser(M)) {
116
- M = compare.clone()
117
- }
118
- }
119
-
120
- return M
121
- }
122
-
123
- // ------------------------------------------
124
- // Creation / parsing functions
125
-
126
- static average = (...fractions: (Fraction | number)[]): Fraction => {
127
- let M = new Fraction().zero()
128
-
129
- for (let f of fractions) {
130
- M.add(f)
131
- }
132
-
133
- M.divide(fractions.length)
134
-
135
- return M
136
- }
137
-
138
- static unique = (fractions: Fraction[], sorted?: boolean): Fraction[] => {
139
- // TODO: make sure it's wokring -> test !
140
- let unique: { [Key: string]: boolean } = {},
141
- distinct: Fraction[] = []
142
- fractions.forEach(x => {
143
- if (!unique[x.clone().reduce().tex]) {
144
- distinct.push(x.clone())
145
- unique[x.tex] = true
146
- }
147
- })
148
-
149
- if (sorted) {
150
- return Fraction.sort(distinct)
151
- } else {
152
- return distinct
153
- }
154
- }
155
-
156
- static sort = (fractions: Fraction[], reverse?: boolean): Fraction[] => {
157
- // Todo make sure it's the correct order, not reverse -> make a test
158
- let sorted = fractions.sort((a, b) => a.value - b.value)
159
-
160
- if (reverse) {
161
- sorted.reverse()
162
- }
163
-
164
- return sorted
165
- }
166
-
167
- isApproximative = (): boolean => {
168
- return this._numerator.toString().length >= 15 && this._denominator.toString().length >= 15
169
- }
170
-
171
- isExact = (): boolean => {
172
- return !this.isApproximative()
173
- }
174
-
175
- // ------------------------------------------
176
- /**
177
- * Parse the value to get the numerator and denominator
178
- * @param value : number or string to parse to get the fraction
179
- * @param denominatorOrPeriodic (optional|number) : length of the periodic part: 2.333333 => 1 or denominator value
180
- */
181
- parse = (value: unknown, denominatorOrPeriodic?: number): Fraction => {
182
- let S: string[];
183
-
184
- // A null value means a zero fraction.
185
- if (value === null || value === "") {
186
- this._numerator = 0;
187
- this._denominator = 1;
188
- return this;
189
- }
190
-
191
- switch (typeof value) {
192
- case "string":
193
- // Split the string value in two parts: Numerator/Denominator
194
- S = value.split('/');
195
-
196
- // Security checks
197
- if (S.length > 2) throw value + " has too many divide signs";
198
- if (S.map(x => x === '' || isNaN(Number(x))).includes(true)) throw value + " is not a valid number"
199
-
200
- if (S.length === 1) {
201
- // No divide sign - it's a number
202
- return this.parse(+S[0]);
203
- } else if (S.length === 2) {
204
- // One divide signe
205
- // We check if the denominator is zero
206
- if (S[1] === '0') {
207
- this._numerator = NaN;
208
- this._denominator = 1;
209
- } else {
210
- this._numerator = +S[0];
211
- this._denominator = +S[1];
212
- }
213
- } else {
214
- // More than one divide sign ?
215
- // This is impossible
216
- this._numerator = NaN;
217
- this._denominator = 1;
218
- }
219
- break;
220
- case "number":
221
- if (Number.isSafeInteger(value)) {
222
- // The given value is an integer
223
- this._numerator = +value;
224
-
225
- if (denominatorOrPeriodic === undefined || !Number.isSafeInteger(denominatorOrPeriodic)) {
226
- this._denominator = 1;
227
- } else {
228
- this._denominator = +denominatorOrPeriodic;
229
- }
230
- } else {
231
- // The given value is a float number
232
- // Get the number of decimals after the float sign
233
- let [unit, decimal] = (value.toString()).split('.')
234
- let p: number = decimal?decimal.length:0;
235
-
236
- // Detect if the decimal part is periodic or not...
237
-
238
-
239
- // Transform the float number in two integer
240
- if (denominatorOrPeriodic === undefined) {
241
- this._numerator = value * Math.pow(10, p);
242
- this._denominator = Math.pow(10, p);
243
- } else if (Number.isSafeInteger(denominatorOrPeriodic)) {
244
- this._numerator = value * Math.pow(10, p) - Math.floor(value * Math.pow(10, p - denominatorOrPeriodic));
245
- this.denominator = Math.pow(10, p) - Math.pow(10, p - denominatorOrPeriodic)
246
- }
247
-
248
- this.reduce()
249
- }
250
- break;
251
- case "object":
252
- if (value instanceof Fraction) {
253
- this._numerator = +value.numerator;
254
- this._denominator = +value.denominator;
255
- }
256
- break;
257
- }
258
- return this;
259
- };
260
-
261
- // ------------------------------------------
262
- // Mathematical operations
263
-
264
- clone = (): Fraction => {
265
- let F = new Fraction();
266
- F.numerator = +this._numerator;
267
- F.denominator = +this._denominator;
268
- return F;
269
- };
270
-
271
- zero = (): Fraction => {
272
- this._numerator = 0;
273
- this._denominator = 1;
274
- return this;
275
- };
276
-
277
- one = (): Fraction => {
278
- this._numerator = 1;
279
- this._denominator = 1;
280
- return this;
281
- };
282
-
283
- infinite = (): Fraction => {
284
- this._numerator = Infinity;
285
- this._denominator = 1;
286
- return this;
287
- };
288
-
289
- invalid = (): Fraction => {
290
- this._numerator = NaN;
291
- this._denominator = 1;
292
- return this;
293
- };
294
-
295
- // ------------------------------------------
296
- opposed = (): Fraction => {
297
- this._numerator = -this._numerator;
298
- return this;
299
- };
300
-
301
- add = (F: Fraction | number): Fraction => {
302
- if (F instanceof Fraction) {
303
- let N: number = this._numerator,
304
- D: number = this._denominator;
305
-
306
- this._numerator = N * F.denominator + F.numerator * D;
307
- this._denominator = D * F.denominator;
308
- } else {
309
- return this.add(new Fraction(F))
310
- }
311
-
312
- return this.reduce();
313
- };
314
-
315
- subtract = (F: Fraction | number): Fraction => {
316
- if (F instanceof Fraction) {
317
- return this.add(F.clone().opposed());
318
- } else {
319
- return this.add(-F)
320
- }
321
- };
322
-
323
- multiply = (F: Fraction | number): Fraction => {
324
- // Parse the value.
325
- // If it's a fraction, return a clone of it
326
- // If it's an integer, return the fraction F/1
327
- let Q = new Fraction(F);
328
-
329
- this._numerator = this._numerator * Q.numerator;
330
- this._denominator = this._denominator * Q.denominator;
331
-
332
- return this.reduce();
333
- };
334
-
335
- xMultiply = (...values: (Fraction | number)[]): Fraction => {
336
- // Parse the value.
337
- // If it's a fraction, return a clone of it
338
- // If it's an integer, return the fraction F/1
339
- for(let value of values){
340
- let F = new Fraction(value)
341
- this._numerator = this._numerator * F.numerator;
342
- this._denominator = this._denominator * F.denominator;
343
- }
344
-
345
- return this;
346
- };
347
-
348
- divide = (F: Fraction | number): Fraction => {
349
- let Q = new Fraction(F);
350
-
351
- if (Q.numerator === 0) {
352
- return new Fraction().infinite();
353
- }
354
-
355
- let N: number = +this._numerator,
356
- D: number = +this._denominator;
357
-
358
- this._numerator = N * Q.denominator;
359
- this._denominator = D * Q.numerator;
360
- return this.reduce();
361
- };
362
-
363
- invert = (): Fraction => {
364
- let n = +this._numerator, d = +this._denominator;
365
- this._numerator = d;
366
- this._denominator = n;
367
-
368
- return this;
369
- }
370
-
371
- pow = (p: number | Fraction): Fraction => {
372
- // TODO: Fraction.pow with a value different than a safe integer !
373
- if (p instanceof Fraction) {
374
- return this.pow(p.value)
375
- }
376
-
377
- this.reduce();
378
- if (p < 0) {
379
- this.invert()
380
- }
381
-
382
- // Check if numerator and denominator are roots of...
383
- // othervise, convert to numeric.
384
- let controlNumerator = Math.floor(Math.pow(this._numerator, Math.abs(p))),
385
- controlDenominator = Math.floor(Math.pow(this._denominator, Math.abs(p)))
386
-
387
- if (controlNumerator ** Math.abs(p) === this._numerator
388
- &&
389
- controlDenominator ** Math.abs(p) === this._denominator) {
390
-
391
- this._numerator = this._numerator ** Math.abs(p);
392
- this._denominator = this._denominator ** Math.abs(p);
393
- } else {
394
- this._numerator = this._numerator ** Math.abs(p);
395
- this._denominator = this._denominator ** Math.abs(p);
396
- }
397
-
398
- return this;
399
- };
400
-
401
- root = (p: number): Fraction => {
402
- // TODO: nth - root of a fraction => this will return another type of coefficient.
403
-
404
- // Check if they are perfect roots..
405
- if (p === 0) {
406
- return this;
407
- }
408
-
409
- // If negative, invert the fraction
410
- if (p < 0) {
411
- this.invert()
412
- }
413
-
414
- let n = Math.pow(this._numerator, Math.abs(1 / p)),
415
- d = Math.pow(this._denominator, Math.abs(1 / p));
416
-
417
- this._numerator = Math.pow(this._numerator, Math.abs(1 / p));
418
- this._denominator = Math.pow(this._denominator, Math.abs(1 / p));
419
- return this;
420
- }
421
-
422
- sqrt = (): Fraction => {
423
- return this.root(2);
424
- }
425
-
426
- abs = (): Fraction => {
427
- this._numerator = Math.abs(this._numerator);
428
- this._denominator = Math.abs(this._denominator);
429
- return this;
430
- };
431
-
432
- // ------------------------------------------
433
- // Mathematical operations specific to fractions
434
-
435
- // ------------------------------------------
436
- reduce = (): Fraction => {
437
- let g = Numeric.gcd(this._numerator, this._denominator);
438
- this._numerator = this._numerator / g;
439
- this._denominator = this._denominator / g;
440
-
441
- if (this._denominator < 0) {
442
- this._denominator = -this._denominator;
443
- this._numerator = -this._numerator;
444
- }
445
- return this;
446
- };
447
-
448
- amplify = (k: number): Fraction => {
449
- if (Number.isSafeInteger(k)) {
450
- this._numerator *= k;
451
- this._denominator *= k;
452
- }
453
- return this;
454
- };
455
-
456
-
457
- // ------------------------------------------
458
- // Compare functions
459
- // ------------------------------------------
460
- /**
461
- * Compare the current coefficient with another coefficient
462
- * @param F (Coefficient) The coefficient to compare
463
- * @param sign (string| default is =): authorized values: =, <, <=, >, >= with some variations.
464
- */
465
- compare = (F: unknown, sign?: string): boolean => {
466
- if (sign === undefined) {
467
- sign = '=';
468
- }
469
-
470
- let compareFraction: Fraction
471
- if (F instanceof Fraction) {
472
- compareFraction = F.clone()
473
- } else {
474
- compareFraction = new Fraction(F)
475
- }
476
-
477
- switch (sign) {
478
- case '>':
479
- return this.value > compareFraction.value;
480
- case ">=" || "=>" || "geq":
481
- return this.value >= compareFraction.value;
482
- case "<":
483
- return this.value < compareFraction.value;
484
- case "<=" || "=>" || "leq":
485
- return this.value <= compareFraction.value;
486
- case "=":
487
- // let F2: Fraction = compareFraction.clone().reduce(),
488
- // F1: Fraction = this.clone().reduce();
489
- // return (F1.numerator === F2.numerator && F1.denominator === F2.denominator);
490
- return this.value === compareFraction.value;
491
- case "<>":
492
- return this.value !== compareFraction.value;
493
- default:
494
- return false;
495
- }
496
- };
497
- /* Compare shortcuts */
498
- lesser = (than: Fraction | number): Boolean => {
499
- return this.compare(than, '<');
500
- };
501
- leq = (than: Fraction | number): Boolean => {
502
- return this.compare(than, '<=');
503
- };
504
- greater = (than: Fraction | number): Boolean => {
505
- return this.compare(than, '>');
506
- };
507
- geq = (than: Fraction | number): Boolean => {
508
- return this.compare(than, '>=');
509
- };
510
- isEqual = (than: Fraction | number): boolean => {
511
- return this.compare(than, '=');
512
- }
513
- isNotEqual = (than: Fraction | number): boolean => {
514
- return this.compare(than, '<>');
515
- }
516
- isOpposed = (p: Fraction): boolean => {
517
- return this.isEqual(p.clone().opposed());
518
- }
519
- isInverted = (p: Fraction): boolean => {
520
- return this.isEqual(new Fraction().one().divide(p.clone()));
521
- }
522
- isZero = (): boolean => {
523
- return this._numerator === 0;
524
- }
525
- isNotZero = (): boolean => {
526
- return this._numerator !== 0;
527
- }
528
- isOne = (): boolean => {
529
- return this._numerator === 1 && this._denominator === 1;
530
- }
531
- isNegativeOne = (): boolean => {
532
- return this._numerator === -1 && this._denominator === 1;
533
- }
534
- isPositive = (): boolean => {
535
- return this.sign() === 1;
536
- }
537
- isNegative = (): boolean => {
538
- return this.sign() === -1;
539
- }
540
- isStrictlyPositive = (): boolean => {
541
- return this.value > 0
542
- }
543
- isStrictlyNegative = (): Boolean => {
544
- return this.value < 0
545
- }
546
- isNaN = (): boolean => {
547
- return isNaN(this._numerator);
548
- }
549
- isInfinity = (): boolean => {
550
- return Math.abs(this._numerator) === Infinity;
551
- }
552
- isFinite = (): boolean => {
553
- return !this.isInfinity() && !this.isNaN();
554
- }
555
- isSquare = (): boolean => {
556
- return Math.sqrt(this._numerator) % 1 === 0 && Math.sqrt(this._denominator) % 1 === 0
557
- }
558
- isReduced = (): boolean => {
559
- return Math.abs(Numeric.gcd(this._numerator, this._denominator)) === 1
560
- }
561
- isNatural = (): boolean => {
562
- return this.isRelative() && this.isPositive()
563
- }
564
- isRelative = (): boolean => {
565
- return this.clone().reduce().denominator === 1
566
- }
567
- isRational = (): boolean => {
568
- return !this.isRelative()
569
- }
570
- isEven = (): boolean => {
571
- return this.isRelative() && this.value % 2 === 0
572
- }
573
- isOdd = (): boolean => {
574
- return this.isRelative() && this.value % 2 === 1
575
- }
576
- sign = (): number => {
577
- return (this._numerator * this._denominator >= 0) ? 1 : -1;
578
- };
579
-
580
-
581
- // TODO: The rest of the functions are not used or unnecessary ?
582
- /**
583
- * Simple function to determine if it's a fraction
584
- */
585
- areEquals = (...F: Fraction[]): boolean => {
586
- for (let i = 0; i < F.length; i++) {
587
- if (!this.isEqual(F[i])) {
588
- return false;
589
- }
590
- }
591
- return true;
592
- };
593
- }