math-exercises 2.1.0 → 2.1.2
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.
- package/lib/exercises/exercise.d.ts +1 -1
- package/lib/exercises/exercise.d.ts.map +1 -1
- package/lib/exercises/math/functions/affines/affineExpressionReading.d.ts.map +1 -1
- package/lib/exercises/math/functions/affines/affineExpressionReading.js +1 -0
- package/lib/exercises/math/functions/affines/interceptReading.d.ts.map +1 -1
- package/lib/exercises/math/functions/affines/interceptReading.js +1 -0
- package/lib/exercises/math/percent/findProportion.d.ts +8 -0
- package/lib/exercises/math/percent/findProportion.d.ts.map +1 -0
- package/lib/exercises/math/percent/findProportion.js +48 -0
- package/lib/exercises/math/percent/index.d.ts +1 -0
- package/lib/exercises/math/percent/index.d.ts.map +1 -1
- package/lib/exercises/math/percent/index.js +1 -0
- package/lib/exercises/math/powers/decimalToScientific.js +4 -4
- package/lib/exercises/math/sequences/arithmetic/recognizeArithmeticFromGraph.d.ts.map +1 -1
- package/lib/exercises/math/sequences/arithmetic/recognizeArithmeticFromGraph.js +4 -1
- package/lib/exercises/math/sequences/arithmetic/recognizeReasonFromGraph.d.ts.map +1 -1
- package/lib/exercises/math/sequences/arithmetic/recognizeReasonFromGraph.js +4 -1
- package/lib/exercises/pc/chemicalElements/atomicStructureOfNucleus.d.ts +8 -0
- package/lib/exercises/pc/chemicalElements/atomicStructureOfNucleus.d.ts.map +1 -0
- package/lib/exercises/pc/chemicalElements/atomicStructureOfNucleus.js +58 -0
- package/lib/exercises/pc/chemicalElements/calculateProtonsNumberFromMass.d.ts +8 -0
- package/lib/exercises/pc/chemicalElements/calculateProtonsNumberFromMass.d.ts.map +1 -0
- package/lib/exercises/pc/chemicalElements/calculateProtonsNumberFromMass.js +63 -0
- package/lib/exercises/pc/chemicalElements/calculateVolumetricMass.d.ts +5 -0
- package/lib/exercises/pc/chemicalElements/calculateVolumetricMass.d.ts.map +1 -0
- package/lib/exercises/pc/chemicalElements/calculateVolumetricMass.js +76 -0
- package/lib/exercises/pc/chemicalElements/findAtomicStructureElement.d.ts +10 -0
- package/lib/exercises/pc/chemicalElements/findAtomicStructureElement.d.ts.map +1 -0
- package/lib/exercises/pc/chemicalElements/findAtomicStructureElement.js +68 -0
- package/lib/exercises/pc/chemicalElements/findValenceElectronsNumberFromElectronicConfiguration.d.ts +8 -0
- package/lib/exercises/pc/chemicalElements/findValenceElectronsNumberFromElectronicConfiguration.d.ts.map +1 -0
- package/lib/exercises/pc/chemicalElements/findValenceElectronsNumberFromElectronicConfiguration.js +58 -0
- package/lib/exercises/pc/chemicalElements/findValenceElectronsNumberFromTable.d.ts +8 -0
- package/lib/exercises/pc/chemicalElements/findValenceElectronsNumberFromTable.d.ts.map +1 -0
- package/lib/exercises/pc/chemicalElements/findValenceElectronsNumberFromTable.js +59 -0
- package/lib/exercises/pc/chemicalElements/identifyRightElectronicConfiguration.d.ts +8 -0
- package/lib/exercises/pc/chemicalElements/identifyRightElectronicConfiguration.d.ts.map +1 -0
- package/lib/exercises/pc/chemicalElements/identifyRightElectronicConfiguration.js +101 -0
- package/lib/exercises/pc/chemicalElements/index.d.ts +9 -0
- package/lib/exercises/pc/chemicalElements/index.d.ts.map +1 -0
- package/lib/exercises/pc/chemicalElements/index.js +24 -0
- package/lib/exercises/pc/chemicalElements/weightPercent.d.ts +10 -0
- package/lib/exercises/pc/chemicalElements/weightPercent.d.ts.map +1 -0
- package/lib/exercises/pc/chemicalElements/weightPercent.js +107 -0
- package/lib/exercises/pc/chemicalEquations.js +1 -1
- package/lib/exercises/pc/forces/gravitationalAttractionValue.d.ts +7 -0
- package/lib/exercises/pc/forces/gravitationalAttractionValue.d.ts.map +1 -0
- package/lib/exercises/pc/forces/gravitationalAttractionValue.js +71 -0
- package/lib/exercises/pc/forces/index.d.ts +2 -0
- package/lib/exercises/pc/forces/index.d.ts.map +1 -0
- package/lib/exercises/pc/forces/index.js +17 -0
- package/lib/exercises/pc/index.d.ts +12 -0
- package/lib/exercises/pc/index.d.ts.map +1 -1
- package/lib/exercises/pc/index.js +14 -0
- package/lib/exercises/pc/math/index.d.ts +2 -0
- package/lib/exercises/pc/math/index.d.ts.map +1 -0
- package/lib/exercises/pc/math/index.js +18 -0
- package/lib/exercises/pc/math/isolateVariables.d.ts +8 -0
- package/lib/exercises/pc/math/isolateVariables.d.ts.map +1 -0
- package/lib/exercises/pc/math/isolateVariables.js +304 -0
- package/lib/exercises/pc/math/proportionnalityCoeffFromLine.d.ts +10 -0
- package/lib/exercises/pc/math/proportionnalityCoeffFromLine.d.ts.map +1 -0
- package/lib/exercises/pc/math/proportionnalityCoeffFromLine.js +81 -0
- package/lib/exercises/pc/motion/recognizeFreeFall.d.ts +1 -0
- package/lib/exercises/pc/motion/recognizeFreeFall.d.ts.map +1 -0
- package/lib/exercises/pc/motion/recognizeFreeFall.js +53 -0
- package/lib/exercises/pc/sound/findPeriodFromGraph.d.ts +8 -0
- package/lib/exercises/pc/sound/findPeriodFromGraph.d.ts.map +1 -0
- package/lib/exercises/pc/sound/findPeriodFromGraph.js +80 -0
- package/lib/exercises/pc/sound/findSoundFrequencyFromPeriod.d.ts +7 -0
- package/lib/exercises/pc/sound/findSoundFrequencyFromPeriod.d.ts.map +1 -0
- package/lib/exercises/pc/sound/findSoundFrequencyFromPeriod.js +51 -0
- package/lib/exercises/pc/sound/findSoundPeriodFromFrequency.d.ts +7 -0
- package/lib/exercises/pc/sound/findSoundPeriodFromFrequency.d.ts.map +1 -0
- package/lib/exercises/pc/sound/findSoundPeriodFromFrequency.js +58 -0
- package/lib/exercises/pc/sound/frequencyComparison.d.ts +9 -0
- package/lib/exercises/pc/sound/frequencyComparison.d.ts.map +1 -0
- package/lib/exercises/pc/sound/frequencyComparison.js +51 -0
- package/lib/exercises/pc/sound/index.d.ts +5 -0
- package/lib/exercises/pc/sound/index.d.ts.map +1 -0
- package/lib/exercises/pc/sound/index.js +20 -0
- package/lib/exercises/pc/waves/findDistanceFromEarth.d.ts +7 -0
- package/lib/exercises/pc/waves/findDistanceFromEarth.d.ts.map +1 -0
- package/lib/exercises/pc/waves/findDistanceFromEarth.js +66 -0
- package/lib/exercises/pc/waves/index.d.ts +2 -0
- package/lib/exercises/pc/waves/index.d.ts.map +1 -0
- package/lib/exercises/pc/waves/index.js +17 -0
- package/lib/exercises/pc/weight/index.d.ts +2 -0
- package/lib/exercises/pc/weight/index.d.ts.map +1 -0
- package/lib/exercises/pc/weight/index.js +17 -0
- package/lib/exercises/pc/weight/weightOnTheMoon.d.ts +8 -0
- package/lib/exercises/pc/weight/weightOnTheMoon.d.ts.map +1 -0
- package/lib/exercises/pc/weight/weightOnTheMoon.js +64 -0
- package/lib/exercises/utils/getAtoms.d.ts +2 -0
- package/lib/exercises/utils/getAtoms.d.ts.map +1 -0
- package/lib/exercises/utils/getAtoms.js +11 -0
- package/lib/exercises/utils/getElectronicConfigurationFromShells.d.ts +2 -0
- package/lib/exercises/utils/getElectronicConfigurationFromShells.d.ts.map +1 -0
- package/lib/exercises/utils/getElectronicConfigurationFromShells.js +19 -0
- package/lib/geogebra/geogebraConstructor.d.ts +2 -0
- package/lib/geogebra/geogebraConstructor.d.ts.map +1 -1
- package/lib/geogebra/geogebraConstructor.js +2 -0
- package/lib/index.d.ts +126 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -0
- package/lib/math/numbers/decimals/decimal.d.ts +3 -3
- package/lib/math/numbers/decimals/decimal.d.ts.map +1 -1
- package/lib/math/numbers/decimals/decimal.js +39 -19
- package/lib/math/utils/random/randfloat.d.ts +1 -1
- package/lib/math/utils/random/randfloat.d.ts.map +1 -1
- package/lib/math/utils/random/randfloat.js +4 -7
- package/lib/math/utils/round.d.ts +2 -1
- package/lib/math/utils/round.d.ts.map +1 -1
- package/lib/math/utils/round.js +10 -3
- package/lib/pc/constants/atoms.d.ts +8 -0
- package/lib/pc/constants/atoms.d.ts.map +1 -0
- package/lib/pc/constants/atoms.js +9 -0
- package/lib/pc/constants/earth.d.ts +9 -0
- package/lib/pc/constants/earth.d.ts.map +1 -0
- package/lib/pc/constants/earth.js +12 -0
- package/lib/pc/constants/gravity.d.ts +10 -0
- package/lib/pc/constants/gravity.d.ts.map +1 -0
- package/lib/pc/constants/gravity.js +16 -0
- package/lib/pc/measure/measure.d.ts +15 -0
- package/lib/pc/measure/measure.d.ts.map +1 -0
- package/lib/pc/measure/measure.js +97 -0
- package/lib/pc/molecularChemistry/atome.d.ts +3 -2
- package/lib/pc/molecularChemistry/atome.d.ts.map +1 -1
- package/lib/pc/molecularChemistry/atome.js +156 -120
- package/lib/pc/molecularChemistry/molecule.d.ts +3 -2
- package/lib/pc/molecularChemistry/molecule.d.ts.map +1 -1
- package/lib/pc/molecularChemistry/molecule.js +11 -0
- package/lib/pc/molecularChemistry/reaction.d.ts +2 -1
- package/lib/pc/molecularChemistry/reaction.d.ts.map +1 -1
- package/lib/pc/molecularChemistry/reaction.js +9 -0
- package/lib/server.d.ts +1 -0
- package/lib/server.d.ts.map +1 -1
- package/lib/server.js +5 -0
- package/lib/tree/nodes/algebraicNode.d.ts +1 -0
- package/lib/tree/nodes/algebraicNode.d.ts.map +1 -1
- package/lib/tree/nodes/complex/complexNode.d.ts.map +1 -1
- package/lib/tree/nodes/equations/equalNode.d.ts.map +1 -1
- package/lib/tree/nodes/equations/equalNode.js +0 -1
- package/lib/tree/nodes/functions/cosNode.d.ts.map +1 -1
- package/lib/tree/nodes/node.d.ts +1 -0
- package/lib/tree/nodes/node.d.ts.map +1 -1
- package/lib/tree/nodes/numbers/numberNode.js +1 -1
- package/lib/tree/nodes/numbers/piNode.d.ts.map +1 -1
- package/lib/tree/nodes/operators/multiplyNode.d.ts +2 -2
- package/lib/tree/nodes/operators/multiplyNode.d.ts.map +1 -1
- package/lib/tree/nodes/operators/multiplyNode.js +6 -5
- package/lib/types/keyIds.d.ts +4 -2
- package/lib/types/keyIds.d.ts.map +1 -1
- package/lib/utils/numberPrototype/toScientific.d.ts +3 -0
- package/lib/utils/numberPrototype/toScientific.d.ts.map +1 -0
- package/lib/utils/numberPrototype/toScientific.js +110 -0
- package/lib/utils/requiresApostropheBefore.d.ts +2 -0
- package/lib/utils/requiresApostropheBefore.d.ts.map +1 -0
- package/lib/utils/requiresApostropheBefore.js +7 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -29,6 +29,7 @@ const numberNode_1 = require("./tree/nodes/numbers/numberNode");
|
|
|
29
29
|
const MathExercises = __importStar(require("./exercises/math"));
|
|
30
30
|
const PCExercises = __importStar(require("./exercises/pc"));
|
|
31
31
|
const infiniteNode_1 = require("./tree/nodes/numbers/infiniteNode");
|
|
32
|
+
const toScientific_1 = require("./utils/numberPrototype/toScientific");
|
|
32
33
|
Number.prototype.toTree = function () {
|
|
33
34
|
const value = this.valueOf();
|
|
34
35
|
if (value === Infinity)
|
|
@@ -40,6 +41,9 @@ Number.prototype.toTree = function () {
|
|
|
40
41
|
Number.prototype.frenchify = function () {
|
|
41
42
|
return (this.valueOf() + "").replace(".", ",");
|
|
42
43
|
};
|
|
44
|
+
Number.prototype.toScientific = function (decimals) {
|
|
45
|
+
return (0, toScientific_1.toScientific)(this.valueOf(), decimals);
|
|
46
|
+
};
|
|
43
47
|
/**
|
|
44
48
|
* TODO
|
|
45
49
|
* Décimal : permettre facilement -0.xxx
|
|
@@ -16,7 +16,7 @@ export declare class Decimal implements Nombre {
|
|
|
16
16
|
precision: number;
|
|
17
17
|
intPart: number;
|
|
18
18
|
decimalPart: string;
|
|
19
|
-
constructor(value: number);
|
|
19
|
+
constructor(value: number | string);
|
|
20
20
|
equals(n: Nombre): boolean;
|
|
21
21
|
/**
|
|
22
22
|
*
|
|
@@ -25,8 +25,8 @@ export declare class Decimal implements Nombre {
|
|
|
25
25
|
*/
|
|
26
26
|
round(precision: number): Nombre;
|
|
27
27
|
multiplyByPowerOfTen(power: number): Decimal;
|
|
28
|
-
toScientificPart():
|
|
29
|
-
toScientificNotation(): NumberNode | MultiplyNode;
|
|
28
|
+
toScientificPart(): number;
|
|
29
|
+
toScientificNotation(decimals?: number): NumberNode | MultiplyNode;
|
|
30
30
|
toRational(): Rational | import("../integer/integer").Integer;
|
|
31
31
|
toTree(): NumberNode;
|
|
32
32
|
toPercentNode(): PercentNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decimal.d.ts","sourceRoot":"","sources":["../../../../src/math/numbers/decimals/decimal.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AAEvE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,8BAAsB,kBAAkB;IACtC,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,GAAE,MAAU,GAAG,MAAM;IAY1E,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO;IAMpE,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO;IAK/D,MAAM,CAAC,gBAAgB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO;CAMrD;AAED,qBAAa,OAAQ,YAAW,MAAM;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,aAAsB;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;gBACR,KAAK,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"decimal.d.ts","sourceRoot":"","sources":["../../../../src/math/numbers/decimals/decimal.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AAEvE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,8BAAsB,kBAAkB;IACtC,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,GAAE,MAAU,GAAG,MAAM;IAY1E,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO;IAMpE,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO;IAK/D,MAAM,CAAC,gBAAgB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO;CAMrD;AAED,qBAAa,OAAQ,YAAW,MAAM;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,aAAsB;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;gBACR,KAAK,EAAE,MAAM,GAAG,MAAM;IASlC,MAAM,CAAC,CAAC,EAAE,MAAM;IAIhB;;;;OAIG;IACH,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;IAIhC,oBAAoB,CAAC,KAAK,EAAE,MAAM;IAkClC,gBAAgB;IA6BhB,oBAAoB,CAAC,QAAQ,CAAC,EAAE,MAAM;IAwCtC,UAAU;IAMV,MAAM;IAIN,aAAa;CAGd"}
|
|
@@ -32,7 +32,7 @@ class DecimalConstructor {
|
|
|
32
32
|
static fromParts(intPart, decimalPart) {
|
|
33
33
|
if (decimalPart.length === 0)
|
|
34
34
|
return new Decimal(Number("" + intPart));
|
|
35
|
-
return new Decimal(
|
|
35
|
+
return new Decimal("" + intPart + "." + decimalPart);
|
|
36
36
|
}
|
|
37
37
|
//returns X.YYYY where X € [0, 9] and first Y is not zero if X is zero
|
|
38
38
|
static randomScientific(precision) {
|
|
@@ -46,7 +46,7 @@ exports.DecimalConstructor = DecimalConstructor;
|
|
|
46
46
|
class Decimal {
|
|
47
47
|
constructor(value) {
|
|
48
48
|
this.type = nombre_1.NumberType.Decimal;
|
|
49
|
-
this.value = value;
|
|
49
|
+
this.value = Number(value);
|
|
50
50
|
this.tex = value + "";
|
|
51
51
|
let [intPartString, decimalPartString] = (value + "").split(".");
|
|
52
52
|
this.intPart = Number(intPartString);
|
|
@@ -90,35 +90,54 @@ class Decimal {
|
|
|
90
90
|
(isNegative ? "-" : "") +
|
|
91
91
|
intPartString.slice(0, power + intPartString.length);
|
|
92
92
|
}
|
|
93
|
-
console.log("in", newIntPart, newFracPart);
|
|
93
|
+
// console.log("in", newIntPart, newFracPart);
|
|
94
94
|
return DecimalConstructor.fromParts(newIntPart, newFracPart);
|
|
95
95
|
}
|
|
96
96
|
toScientificPart() {
|
|
97
|
-
if (!this.decimalPart.length)
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
if (!this.decimalPart.length) {
|
|
98
|
+
if (this.intPart < 10 && this.intPart > -10)
|
|
99
|
+
return this.intPart;
|
|
100
|
+
let nb = "";
|
|
101
|
+
const intString = this.intPart.toString();
|
|
102
|
+
if (this.intPart < 0)
|
|
103
|
+
nb += "-" + intString[1] + "." + intString.slice(2);
|
|
104
|
+
else
|
|
105
|
+
nb += this.intPart.toString()[0] + "." + intString.slice(1);
|
|
106
|
+
return Number(nb);
|
|
107
|
+
}
|
|
102
108
|
if (this.intPart === 0) {
|
|
103
109
|
//true for -0
|
|
104
110
|
const firstNonZeroIndex = this.decimalPart
|
|
105
111
|
.split("")
|
|
106
112
|
.findIndex((el) => Number(el) !== 0);
|
|
107
|
-
return
|
|
108
|
-
this.decimalPart
|
|
113
|
+
return Number((this.tex[0] === "-"
|
|
114
|
+
? `-${this.decimalPart[firstNonZeroIndex]}.`
|
|
115
|
+
: `${this.decimalPart[firstNonZeroIndex]}.`) +
|
|
116
|
+
this.decimalPart.slice(firstNonZeroIndex + 1));
|
|
109
117
|
}
|
|
110
118
|
const intString = this.intPart + "";
|
|
111
|
-
return
|
|
119
|
+
return Number((this.tex[0] === "-" ? "-" + this.tex[1] : this.tex[0]) +
|
|
112
120
|
"." +
|
|
113
121
|
(this.tex[0] === "-" ? intString.slice(2) : intString.slice(1)) +
|
|
114
|
-
this.decimalPart)
|
|
122
|
+
this.decimalPart);
|
|
115
123
|
}
|
|
116
|
-
toScientificNotation() {
|
|
124
|
+
toScientificNotation(decimals) {
|
|
117
125
|
const intString = this.intPart + "";
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
126
|
+
if (this.intPart > -10 && this.intPart < 10 && this.intPart !== 0) {
|
|
127
|
+
if (decimals === undefined)
|
|
128
|
+
return this.toTree();
|
|
129
|
+
return new numberNode_1.NumberNode((0, round_1.round)(this.value, decimals), (0, round_1.roundSignificant)(this.value, decimals));
|
|
130
|
+
}
|
|
131
|
+
let value = decimals === undefined
|
|
132
|
+
? this.toScientificPart()
|
|
133
|
+
: (0, round_1.round)(this.toScientificPart(), decimals);
|
|
134
|
+
// console.log(value);
|
|
135
|
+
let power = 0;
|
|
136
|
+
if (value >= 10) {
|
|
137
|
+
value = 1;
|
|
138
|
+
power = 1;
|
|
139
|
+
}
|
|
140
|
+
const decNode = new numberNode_1.NumberNode(value, decimals !== undefined ? (0, round_1.roundSignificant)(value, decimals) : undefined);
|
|
122
141
|
let leadingZeros = 0;
|
|
123
142
|
const nbs = this.decimalPart.split("").map(Number);
|
|
124
143
|
for (let i = 0; i < nbs.length; i++) {
|
|
@@ -126,7 +145,8 @@ class Decimal {
|
|
|
126
145
|
break;
|
|
127
146
|
leadingZeros++;
|
|
128
147
|
}
|
|
129
|
-
|
|
148
|
+
power +=
|
|
149
|
+
this.intPart === 0 ? -(leadingZeros + 1) : (this.intPart + "").length - 1;
|
|
130
150
|
if (power === 0)
|
|
131
151
|
return this.toTree();
|
|
132
152
|
if (power === 1)
|
|
@@ -137,7 +157,7 @@ class Decimal {
|
|
|
137
157
|
return new rational_1.Rational(this.multiplyByPowerOfTen(this.precision).value, 10 ** this.precision).simplify();
|
|
138
158
|
}
|
|
139
159
|
toTree() {
|
|
140
|
-
return new numberNode_1.NumberNode(this.value);
|
|
160
|
+
return new numberNode_1.NumberNode(this.value, this.tex);
|
|
141
161
|
}
|
|
142
162
|
toPercentNode() {
|
|
143
163
|
return new percentNode_1.PercentNode(this.multiplyByPowerOfTen(2).value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"randfloat.d.ts","sourceRoot":"","sources":["../../../../src/math/utils/random/randfloat.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"randfloat.d.ts","sourceRoot":"","sources":["../../../../src/math/utils/random/randfloat.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,eAAO,MAAM,SAAS,MAAO,MAAM,MAAM,MAAM,YAAY,MAAM,KAAG,MAInE,CAAC"}
|
|
@@ -4,15 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.randfloat = void 0;
|
|
7
|
-
const
|
|
7
|
+
const round_1 = require("../round");
|
|
8
|
+
const randfloat = (a, b, roundTo) => {
|
|
8
9
|
if (b === undefined)
|
|
9
10
|
return Math.random() * a;
|
|
10
|
-
if (
|
|
11
|
+
if (roundTo === undefined)
|
|
11
12
|
return a + Math.random() * (b - a);
|
|
12
|
-
|
|
13
|
-
do {
|
|
14
|
-
res = a + Math.random() * (b - a);
|
|
15
|
-
} while (excludes.includes(res));
|
|
16
|
-
return res;
|
|
13
|
+
return (0, round_1.round)(a + Math.random() * (b - a), roundTo);
|
|
17
14
|
};
|
|
18
15
|
exports.randfloat = randfloat;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export declare function round(x: number, precision: number): number;
|
|
1
|
+
export declare function round(x: number, precision: number, fillDecimals?: boolean): number;
|
|
2
|
+
export declare function roundSignificant(x: number, precision: number): string;
|
|
2
3
|
//# sourceMappingURL=round.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"round.d.ts","sourceRoot":"","sources":["../../../src/math/utils/round.ts"],"names":[],"mappings":"AAEA,wBAAgB,KAAK,
|
|
1
|
+
{"version":3,"file":"round.d.ts","sourceRoot":"","sources":["../../../src/math/utils/round.ts"],"names":[],"mappings":"AAEA,wBAAgB,KAAK,CACnB,CAAC,EAAE,MAAM,EACT,SAAS,EAAE,MAAM,EACjB,YAAY,CAAC,EAAE,OAAO,GACrB,MAAM,CAKR;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,UAK5D"}
|
package/lib/math/utils/round.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.round = void 0;
|
|
3
|
+
exports.roundSignificant = exports.round = void 0;
|
|
4
4
|
const epsilon_1 = require("../numbers/epsilon");
|
|
5
|
-
function round(x, precision) {
|
|
6
|
-
return Math.round((x + epsilon_1.EPSILON) * Math.pow(10, precision)) /
|
|
5
|
+
function round(x, precision, fillDecimals) {
|
|
6
|
+
return (Math.round((x + epsilon_1.EPSILON) * Math.pow(10, precision)) /
|
|
7
|
+
Math.pow(10, precision));
|
|
7
8
|
}
|
|
8
9
|
exports.round = round;
|
|
10
|
+
function roundSignificant(x, precision) {
|
|
11
|
+
const rounded = Math.round((x + epsilon_1.EPSILON) * Math.pow(10, precision)) /
|
|
12
|
+
Math.pow(10, precision);
|
|
13
|
+
return rounded.toFixed(precision).replace(".", ",");
|
|
14
|
+
}
|
|
15
|
+
exports.roundSignificant = roundSignificant;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"atoms.d.ts","sourceRoot":"","sources":["../../../src/pc/constants/atoms.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,KAAK,gBAAgB,GAAG;IACtB,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,gBAIzB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nucleonMass = void 0;
|
|
4
|
+
const measure_1 = require("../measure/measure");
|
|
5
|
+
exports.nucleonMass = {
|
|
6
|
+
value: new measure_1.Measure(1.67, -27),
|
|
7
|
+
// value: 1.67 * Math.pow(10, -27),
|
|
8
|
+
unit: "\\text{kg}",
|
|
9
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Measure } from "../measure/measure";
|
|
2
|
+
type PhysicalConstant = {
|
|
3
|
+
measure: Measure;
|
|
4
|
+
unit: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const earthRayon: PhysicalConstant;
|
|
7
|
+
export declare const earthMass: PhysicalConstant;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=earth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"earth.d.ts","sourceRoot":"","sources":["../../../src/pc/constants/earth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,KAAK,gBAAgB,GAAG;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,gBAGxB,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,gBAGvB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.earthMass = exports.earthRayon = void 0;
|
|
4
|
+
const measure_1 = require("../measure/measure");
|
|
5
|
+
exports.earthRayon = {
|
|
6
|
+
measure: new measure_1.Measure(6.38, 3),
|
|
7
|
+
unit: "\\text{km}",
|
|
8
|
+
};
|
|
9
|
+
exports.earthMass = {
|
|
10
|
+
measure: new measure_1.Measure(5.97, 24),
|
|
11
|
+
unit: "\\text{kg}",
|
|
12
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Measure } from "../measure/measure";
|
|
2
|
+
type PhysicalConstant = {
|
|
3
|
+
measure: Measure;
|
|
4
|
+
unit: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const earthGravity: PhysicalConstant;
|
|
7
|
+
export declare const moonGravity: PhysicalConstant;
|
|
8
|
+
export declare const earthG: PhysicalConstant;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=gravity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gravity.d.ts","sourceRoot":"","sources":["../../../src/pc/constants/gravity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,KAAK,gBAAgB,GAAG;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,gBAG1B,CAAC;AACF,eAAO,MAAM,WAAW,EAAE,gBAGzB,CAAC;AACF,eAAO,MAAM,MAAM,EAAE,gBAGpB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.earthG = exports.moonGravity = exports.earthGravity = void 0;
|
|
4
|
+
const measure_1 = require("../measure/measure");
|
|
5
|
+
exports.earthGravity = {
|
|
6
|
+
measure: new measure_1.Measure(9.80665, 0),
|
|
7
|
+
unit: "\\text{N}\\cdot\\text{kg}^{-1}",
|
|
8
|
+
};
|
|
9
|
+
exports.moonGravity = {
|
|
10
|
+
measure: new measure_1.Measure(1.622),
|
|
11
|
+
unit: "\\text{N}\\cdot\\text{kg}^{-1}",
|
|
12
|
+
};
|
|
13
|
+
exports.earthG = {
|
|
14
|
+
measure: new measure_1.Measure(6.67, -11),
|
|
15
|
+
unit: "\\text{N}\\cdot\\text{m}^2\\cdot\\text{kg}^{-2}",
|
|
16
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ToTexOptions } from "../../tree/nodes/node";
|
|
2
|
+
export declare class Measure {
|
|
3
|
+
exponent: number;
|
|
4
|
+
significantPart: number;
|
|
5
|
+
constructor(value: number, exponent?: number);
|
|
6
|
+
times(n: number | Measure): Measure;
|
|
7
|
+
divide(n: number | Measure): Measure;
|
|
8
|
+
toTex(opts?: ToTexOptions): string;
|
|
9
|
+
/**
|
|
10
|
+
* n = nb decimals
|
|
11
|
+
*/
|
|
12
|
+
toSignificant(n: number): Measure;
|
|
13
|
+
evaluate(): number;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=measure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"measure.d.ts","sourceRoot":"","sources":["../../../src/pc/measure/measure.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAKrD,qBAAa,OAAO;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;gBAEZ,KAAK,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAU;IAmD/C,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO;IAQzB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO;IAS1B,KAAK,CAAC,IAAI,CAAC,EAAE,YAAY;IAuBzB;;OAEG;IACH,aAAa,CAAC,CAAC,EAAE,MAAM;IAcvB,QAAQ;CAGT"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Measure = void 0;
|
|
4
|
+
const round_1 = require("../../math/utils/round");
|
|
5
|
+
const numberNode_1 = require("../../tree/nodes/numbers/numberNode");
|
|
6
|
+
const multiplyNode_1 = require("../../tree/nodes/operators/multiplyNode");
|
|
7
|
+
const powerNode_1 = require("../../tree/nodes/operators/powerNode");
|
|
8
|
+
class Measure {
|
|
9
|
+
constructor(value, exponent = 0) {
|
|
10
|
+
// console.log("bf", value, exponent);
|
|
11
|
+
if (value === 0) {
|
|
12
|
+
this.significantPart = 0;
|
|
13
|
+
this.exponent = 0;
|
|
14
|
+
}
|
|
15
|
+
else if (value >= 10) {
|
|
16
|
+
const stringValue = value.toString();
|
|
17
|
+
const length = stringValue.split(".")[0].length - 1;
|
|
18
|
+
this.exponent = exponent + length;
|
|
19
|
+
this.significantPart = Number(stringValue[0] + "." + stringValue.replace(".", "").slice(1));
|
|
20
|
+
}
|
|
21
|
+
else if (value <= -10) {
|
|
22
|
+
const stringValue = value.toString();
|
|
23
|
+
const length = stringValue.split(".")[0].length - 2;
|
|
24
|
+
this.exponent = exponent + length;
|
|
25
|
+
this.significantPart = Number("-" + stringValue[1] + "." + stringValue.replace(".", "").slice(1));
|
|
26
|
+
}
|
|
27
|
+
else if (value > 0 && value < 1) {
|
|
28
|
+
const stringValue = value.toString();
|
|
29
|
+
const firstSignificantIndex = stringValue
|
|
30
|
+
.split("")
|
|
31
|
+
.findIndex((el) => el.match(/[1-9]/));
|
|
32
|
+
const length = firstSignificantIndex - 1;
|
|
33
|
+
this.exponent = exponent - length;
|
|
34
|
+
this.significantPart = Number(stringValue[firstSignificantIndex] +
|
|
35
|
+
"." +
|
|
36
|
+
stringValue.slice(firstSignificantIndex + 1));
|
|
37
|
+
}
|
|
38
|
+
else if (value > -1 && value < 0) {
|
|
39
|
+
const stringValue = value.toString();
|
|
40
|
+
const firstSignificantIndex = stringValue
|
|
41
|
+
.split("")
|
|
42
|
+
.findIndex((el) => el.match(/[1-9]/));
|
|
43
|
+
const length = firstSignificantIndex - 2;
|
|
44
|
+
this.exponent = exponent - length;
|
|
45
|
+
this.significantPart = Number("-" +
|
|
46
|
+
stringValue[firstSignificantIndex] +
|
|
47
|
+
"." +
|
|
48
|
+
stringValue.slice(firstSignificantIndex + 1));
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
this.significantPart = value;
|
|
52
|
+
this.exponent = exponent;
|
|
53
|
+
}
|
|
54
|
+
// console.log("after", this.significantPart, this.exponent);
|
|
55
|
+
}
|
|
56
|
+
times(n) {
|
|
57
|
+
if (typeof n === "number")
|
|
58
|
+
return new Measure(this.significantPart * n, this.exponent);
|
|
59
|
+
return new Measure(this.significantPart * n.significantPart, this.exponent + n.exponent);
|
|
60
|
+
}
|
|
61
|
+
divide(n) {
|
|
62
|
+
if (typeof n === "number")
|
|
63
|
+
return new Measure(this.significantPart / n, this.exponent);
|
|
64
|
+
return new Measure(this.significantPart / n.significantPart, this.exponent - n.exponent);
|
|
65
|
+
}
|
|
66
|
+
toTex(opts) {
|
|
67
|
+
const decimals = opts?.scientific;
|
|
68
|
+
const nbTree = decimals === undefined
|
|
69
|
+
? this.significantPart.toTree()
|
|
70
|
+
: new numberNode_1.NumberNode(this.significantPart, (0, round_1.roundSignificant)(this.significantPart, decimals));
|
|
71
|
+
if (this.exponent === 0) {
|
|
72
|
+
return nbTree.toTex();
|
|
73
|
+
}
|
|
74
|
+
if (this.exponent === 1) {
|
|
75
|
+
return new multiplyNode_1.MultiplyNode(nbTree, (10).toTree()).toTex({
|
|
76
|
+
scientific: decimals,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return new multiplyNode_1.MultiplyNode(nbTree, new powerNode_1.PowerNode((10).toTree(), this.exponent.toTree())).toTex({ scientific: decimals });
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* n = nb decimals
|
|
83
|
+
*/
|
|
84
|
+
toSignificant(n) {
|
|
85
|
+
const significantString = this.significantPart.toString();
|
|
86
|
+
const [intPart, fracPart] = significantString.split(".");
|
|
87
|
+
if (n === 0)
|
|
88
|
+
return new Measure(Number(intPart), this.exponent);
|
|
89
|
+
return new Measure(Number(intPart + "." + fracPart.slice(0, n)), this.exponent);
|
|
90
|
+
}
|
|
91
|
+
//gravité = 9.32423432
|
|
92
|
+
//new Measure(9432432).toSignificant(1).times(39)
|
|
93
|
+
evaluate() {
|
|
94
|
+
return this.significantPart * Math.pow(10, this.exponent);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.Measure = Measure;
|
|
@@ -5,13 +5,14 @@ export declare class Atome {
|
|
|
5
5
|
symbole: AtomSymbols;
|
|
6
6
|
numeroAtomique: number;
|
|
7
7
|
masseAtomique: number;
|
|
8
|
-
|
|
8
|
+
electronsShells?: number[];
|
|
9
9
|
famille: string;
|
|
10
10
|
etatStandard: string;
|
|
11
11
|
couleur: string;
|
|
12
12
|
masseVolumique: number;
|
|
13
13
|
pointFusion: number;
|
|
14
|
-
|
|
14
|
+
valenceElectronsNumber?: number;
|
|
15
|
+
constructor(name: KeyId, symbole: AtomSymbols, numeroAtomique: number, masseAtomique: number, famille: string, etatStandard: string, couleur: string, masseVolumique: number, pointFusion: number, electronsShells?: number[], valenceElectronsNumber?: number);
|
|
15
16
|
}
|
|
16
17
|
export declare const atomes: Atome[];
|
|
17
18
|
//# sourceMappingURL=atome.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atome.d.ts","sourceRoot":"","sources":["../../../src/pc/molecularChemistry/atome.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,qBAAa,KAAK;IAChB,IAAI,EAAE,KAAK,CAAC;IACZ,OAAO,EAAE,WAAW,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,
|
|
1
|
+
{"version":3,"file":"atome.d.ts","sourceRoot":"","sources":["../../../src/pc/molecularChemistry/atome.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,qBAAa,KAAK;IAChB,IAAI,EAAE,KAAK,CAAC;IACZ,OAAO,EAAE,WAAW,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,sBAAsB,CAAC,EAAE,MAAM,CAAC;gBAG9B,IAAI,EAAE,KAAK,EACX,OAAO,EAAE,WAAW,EACpB,cAAc,EAAE,MAAM,EACtB,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,MAAM,EACtB,WAAW,EAAE,MAAM,EACnB,eAAe,CAAC,EAAE,MAAM,EAAE,EAC1B,sBAAsB,CAAC,EAAE,MAAM;CAclC;AAED,eAAO,MAAM,MAAM,EAAE,KAAK,EA86CzB,CAAC"}
|