math-helper
v1.0.8
Published
## Installation ``` npm install math-helper --save ```
Downloads
4
Readme
math-helper
Installation
npm install math-helper --save
Docs
Index
- General
- isPrime(n: number): boolean
- nextPrime(n: number): number
- isEven(num: number): boolean
- isEvenBitwise(num: number): boolean
- log(base: number, value: number): number
- powerOfTwo(num: number): boolean
- isDivisibleByPowOf2(num: number, divisor: number): boolean
- isDivisible(num: number, divisor: number): boolean
- bitForNumberByBase(num: number, base: number, n_bits: number): number
- factorial(num: number, tmp_fact?: number): number
- Chaining (W.I.P.)
- Geometry
- plane(a:number, b:number, c:number, d:number):Polynomial3D
- projectOnPlane(polynomial:Polynomial2D, plane:Polynomial3D):Polynomial3D
- parabola(a:number, b:number, c:number):Polynomial2D
- parabolaParametric(a:number, from:number, to:number, step:number):Array<Array>
- ellipse(cx:number, cy:number, a:number, b:number):Polynomial2D
- ellipseParametric(cx:number, cy:number, a:number, b:number, rad:number): Array<Array>
- Chaining (W.I.P.)
- Statistic
- arithmeticMean(data:Array):number
- arithmeticWeightedMean(data:Array<Array>):number
- linearRegression(data:Array<Array>):Array<Array>
- binomialCoefficient(n:number, m:number):number
- howManyPermutationsR(data:Array):number
- howManyPermutations(data:Array):number
- howManyDispositionsR(data:Array, m:number):number
- howManyDispositions(data:Array, m:number):number
- howManyCombinationsR(data:Array, m:number):number
- howManyCombinations(data:Array, m:number):number
- Chaining (W.I.P.)
- Trigonometry
- Common (W.I.P.)
General
isPrime(n: number): boolean
import * as MH from 'math-helper';
let is_prime:boolean = MH.General.isPrime(13);
console.log(is_prime); // true
let is_not_prime:boolean = MH.General.isPrime(14);
console.log(is_not_prime); // false
nextPrime(n: number): number
import * as MH from 'math-helper';
let next_prime:number = MH.General.nextPrime(12);
console.log(next_prime); // 13
isEven(num: number): boolean;
import * as MH from 'math-helper';
console.log(MH.General.isEven(1223)); // false
console.log(MH.General.isEven(1222)); // true
isEvenBitwise(num: number): boolean
Come la precedente ma utilizza operazioni bitwise, utile nel caso di grandi iterazioni
log(base: number, value: number): number
import * as MH from 'math-helper';
let log:number = MH.General.isEven(12, 144);
console.log(log); // 2
È possibile specificare una base arbitraria (N.B.: non sono ancora presenti controlli su base e argomento)
powerOfTwo(num: number): boolean
import * as MH from 'math-helper';
let result:number = MH.General.powerOfTwo(12);
console.log(result); // 4096
Calcole le potenze di due specificando l'esponente, con operazioni bitwise
isDivisibleByPowOf2(num: number, divisor: number): boolea
import * as MH from 'math-helper';
let is_divisible: boolean = MH.General.isDivisibleByPowOf2(1234, 16);
console.log(is_divisible); // false
Controlla se un numero è divisibile per una potenza di 2 con operazioni bitwise, non funziona correttamente se si passa un divisore che non sia potenza di 2
isDivisible(num: number, divisor: number): boolean
Come il precedente ma usa solo l'operatore % e non ha limitazioni per i dati in ingresso
bitForNumberByBase(num: number, base: number, n_bits: number): number
import * as MH from 'math-helper';
let nbit:number = MH.General.bitForNumberByBase(1234, 16); // 1234 -> 0x4D2
console.log(nbit); // 3
Fornisce il numero di bit necessari a rappresentare il numero in ingresso in funzione dalla base fornita
factorial(num: number, tmp_fact?: number): number
import * as MH from 'math-helper';
let factorial:number = MH.General.factorial(17);
console.log(factorial); // 355687428096000
Calcolo con funzione tail recursive
Chaining (WIP)
chain(initial_value:any):GeneralChain
import * as MH from 'math-helper';
MH.General.chain(3);
Geometry
plane(a:number, b:number, c:number, d:number):Polynomial3D
import * as MH from 'math-helper';
let data:Array<Array<number>> = Array.from({length: 100}, () => [Math.floor(Math.random() * 100), Math.floor(Math.random() * 100)]);
let plane:Array<number> = MH.Geometry.plane(2, 3, 4)(data);
console.log(plane);
projectOnPlane(polynomial:Polynomial2D, plane:Polynomial3D):Polynomial3D
import * as MH from 'math-helper';
let data:Array<Array<number>> = Array.from({length: 100}, () => [Math.floor(Math.random() * 100), Math.floor(Math.random() * 100)]);
let plane:MH.Polynomial3D = MH.Geometry.plane(2, 3, 4);
let parabola:MH.Polynomial2D = MH.Geometry.parabola(2, 3, 4);
let projection:Array<number> = MH.Geometry.projectOnPlane(parabola, plane)(data);
console.log(projection);
parabola(a:number, b:number, c:number):Polynomial2D
import * as MH from 'math-helper';
let data:Array<number> = Array.from({length: 100}, () => Math.floor(Math.random() * 100));
let parabola:Array<number> = MH.Geometry.parabola(2, 3, 4)(data);
console.log(parabola);
parabolaParametric(a:number, from:number, to:number, step:number):Array<Array>
import * as MH from 'math-helper';
let parabola:Array<number> = MH.Geometry.parabolaParametric(2, 0, 100, 0.01);
console.log(parabola);
ellipse(cx:number, cy:number, a:number, b:number):Polynomial2D
import * as MH from 'math-helper';
let data:Array<number> = Array.from({length: 100}, () => Math.floor(Math.random() * 100));
let ellipse:Array<number> = MH.Geometry.ellipse(2, 3, 4, 5)(data);
console.log(ellipse);
ellipseParametric(cx:number, cy:number, a:number, b:number, rad:number): Array<Array>
import * as MH from 'math-helper';
let ellipse:Array<number> = MH.Geometry.ellipseParametric(2, 3, 4, 5, 0.1);
console.log(ellipse);
Chaining (WIP)
chain(initial_value:any):GeometryChain
import * as MH from 'math-helper';
MH.Geometry.chain(3);
Statistic
arithmeticMean(data:Array):number
import * as MH from 'math-helper';
let data:Array<number> = Array.from({length: 100}, () => Math.floor(Math.random() * 100));
let mean:Array<number> = MH.Statistic.arithmeticMean(data);
console.log(mean);
arithmeticWeightedMean(data:Array<Array>):number
import * as MH from 'math-helper';
let data:Array<number> = Array.from({length: 100}, () => Math.floor(Math.random() * 100));
let mean:Array<number> = MH.Statistic.arithmeticWeightedMean(data);
console.log(mean);
linearRegression(data:Array<Array>):Array<Array>
import * as MH from 'math-helper';
let data:Array<Array<number>> = Array.from({length: 100}, () => [Math.floor(Math.random() * 100), Math.floor(Math.random() * 100)]);
let regression:Array<Array<number>> = MH.Statistic.linearRegression(data);
console.log(regression);
binomialCoefficient(n:number, m:number):number
import * as MH from 'math-helper';
let bc:Array<Array<number>> = MH.Statistic.binomialCoefficient(5, 2);
console.log(bc); // 10
howManyPermutationsR(data:Array):number
import * as MH from 'math-helper';
let data:Array<number> = Array.from({length: 100}, () => Math.floor(Math.random() * 100));
let permutations:number = MH.Statistic.howManyPermutationsR(data);
console.log(permutations);
Permutazioni con ripetizione
howManyPermutations(data:Array):number
import * as MH from 'math-helper';
let data:Array<number> = Array.from({length: 100}, () => Math.floor(Math.random() * 100));
let permutations:number = MH.Statistic.howManyPermutations(data);
console.log(permutations);
howManyDispositionsR(data:Array, m:number):number
import * as MH from 'math-helper';
let data:Array<number> = Array.from({length: 100}, () => Math.floor(Math.random() * 100));
let dispositions:number = MH.Statistic.howManyDispositionsR(data);
console.log(dispositions);
Disposizioni con ripetizione
howManyDispositions(data:Array, m:number):number
import * as MH from 'math-helper';
let data:Array<number> = Array.from({length: 100}, () => Math.floor(Math.random() * 100));
let dispositions:number = MH.Statistic.howManyDispositions(data);
console.log(dispositions);
howManyCombinationsR(data:Array, m:number):number
import * as MH from 'math-helper';
let data:Array<number> = Array.from({length: 100}, () => Math.floor(Math.random() * 100));
let combinations:number = MH.Statistic.howManyCombinationsR(data);
console.log(combinations);
Combinazioni con ripetizione
howManyCombinations(data:Array, m:number):number
import * as MH from 'math-helper';
let data:Array<number> = Array.from({length: 100}, () => Math.floor(Math.random() * 100));
let combinations:number = MH.Statistic.howManyCombinations(data);
console.log(combinations);
Chaining (WIP)
chain(initial_value:any):StatisticChain
import * as MH from 'math-helper';
MH.Statistic.chain(3);
Trigonometry
sinWithAmplitude(rad:number, amplitude:number):number
import * as MH from 'math-helper';
let sin:number = MH.Trigonometry.sinWithAmplitude(Math.PI/6, 3);
console.log(sin);
sinWithShift(rad:number, shift:number):number
import * as MH from 'math-helper';
let sin:number = MH.Trigonometry.sinWithShift(Math.PI/6, 3);
console.log(sin);
cosWithAmplitude(rad:number, amplitude:number):number
import * as MH from 'math-helper';
let cos:number = MH.Trigonometry.cosWithAmplitude(Math.PI/6, 3);
console.log(cos);
cosWithShift(rad:number, shift:number):number
import * as MH from 'math-helper';
let cos:number = MH.Trigonometry.cosWithShift(Math.PI/6, 3);
console.log(cos);
Chaining (WIP)
chain(initial_value:any):TrigonometryChain
import * as MH from 'math-helper';
MH.Trigonometry.chain(3);
Common (WIP)
chainWith<T extends any, O extends any>(class_ref:T, curr_value?:any):O
import * as MH from 'math-helper';
MH.General
.chain(3)
.bitForNumberByBase(6, 8)
.chainWith<MH.Geometry, MH.GeometryChain>(MH.Geometry, Math.PI/12)
.ellipseParametric(3, 2,4,5)
.done()
switchTo(class_ref:T): T
import * as MH from 'math-helper';
MH.General
.chain(3)
.bitForNumberByBase(6, 8)
.switchTo(MH.Geometry)
.chain(Math.PI/12)
.ellipseParametric(3, 2,4,5)
.done()
done():any
import * as MH from 'math-helper';
MH.General
.chain(3)
.bitForNumberByBase(6, 8)
.switchTo(MH.Geometry)
.chain(Math.PI/12)
.ellipseParametric(3, 2,4,5)
.done()