How to use the divide function from mathjs

Find comprehensive JavaScript mathjs.divide code examples handpicked from public code repositorys.

30
31
32
33
34
35
36
37
38
39
} else if (decimals > 0) {
    const multipliedNumber = math.multiply(
        math.fraction(number),
        math.pow(10, decimals)
    );
    const dividedNumber = math.divide(
        math.floor(multipliedNumber),
        math.pow(10, decimals)
    );
    return math.number(dividedNumber);
fork icon211
star icon236
watch icon0

+ 3 other calls in file

594
595
596
597
598
599
600
601
602
603
604


/** Calculates how many seconds it will take for the algorithm to finish multiplied
 *  by 10. Multiplied by 10 to prevent rounding errors. */
function calculateRunningTime(cities) {
  var factorialTemp = Mathjs.factorial(cities - 1);
  var numPaths = Mathjs.divide(factorialTemp, 2);
  // The number of seconds is numPaths / 10 but we are now multiplying by 10 to prevent
  // rounding errors so return numPaths. This will be divided by 10 in calculateTimeUnits() when we
  // divide seconds by secondsInUnitOfTime (both are multiplied by 10).

fork icon75
star icon325
watch icon0

+ 2 other calls in file

981
982
983
984
985
986
987
988
989
	'generateOrderFeeData',
	'discount percentage',
	opts.discount
);

const discountToBigNum = math.divide(
	math.bignumber(opts.discount),
	math.bignumber(100)
);
fork icon206
star icon234
watch icon14

4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337


	var eigen = [0, 0];


	var x = math.add(M[0][0], M[1][1]);


	eigen[0] = math.divide(math.add(x, math.sqrt( math.add(math.multiply(math.multiply(4, M[0][1]), M[1][0]), math.pow( math.subtract(M[0][0], M[1][1]), 2)))), 2);
	eigen[1] = math.divide(math.subtract(x, math.sqrt( math.add(math.multiply(math.multiply(4, M[0][1]), M[1][0]), math.pow( math.subtract(M[0][0], M[1][1]), 2)))), 2);


	return eigen;
};
fork icon43
star icon207
watch icon14

+ 315 other calls in file

5
6
7
8
9
10
11
12
13
14
const cadd = math.sum;
const csub = math.subtract;
const cdiv = math.divide;
const cmul = math.multiply;
const cmul_i = z => math.multiply(z, I);
const creciprocal = z => math.divide(1, z);
const csin = math.sin;
const cexp = math.exp;
const clog = math.log;
const csqrt = math.sqrt;
fork icon8
star icon29
watch icon3

+ 11 other calls in file

29
30
31
32
33
34
35
36
37
38
sub: math.subtract,
neg: math.unaryMinus,
mul: math.multiply,
div: math.divide,
mod,
reciprocal: z => math.divide(1, z),
component_mul: (z, alpha) => math.complex(alpha*z.re, alpha*z.im),
component_mul_prelog: (z, alpha) => math.complex(math.exp(alpha)*z.re, math.exp(alpha)*z.im),
real: math.re,
imag: math.im,
fork icon8
star icon29
watch icon3

+ 6 other calls in file

170
171
172
173
174
175
176
177
178
179
else if (math.equal(valueGE, targetValue)) {
        item.volume = volumeGE;
}
else {
        const d = math.subtract(valueGE, valueLE);
        const p = math.divide(math.subtract(targetValue, valueLE), d);
        // console.log({d, p})
        // console.log(math.multiply(math.subtract(1, p), volumeLE))
        // console.log(math.multiply(p, volumeGE))
        item.volume = math.add(math.multiply(math.subtract(1, p), volumeLE), math.multiply(p, volumeGE));
fork icon0
star icon9
watch icon3

21
22
23
24
25
26
27
28
29
};

getBz() {
  const h=10*this.r2, z=this.z1, omega=maths.dotMultiply(this.f, (2*Math.PI)), wireTurnsDensity=this.wireTurn*this.cur/((this.r2-this.r1)*(this.z2-this.z1));
  const coef=Math.PI*4.0e-7*wireTurnsDensity;
  let q = maths.divide(J1root.slice(0,this.ns+1), h);

  let eqz_ = maths.subtract(maths.exp(maths.dotMultiply(q, -1*(this.z1-z))), maths.exp(maths.dotMultiply(q, -1*(this.z2-z))));
  let eqz = maths.subtract(maths.exp(maths.dotMultiply(q, -1*(this.z1+z))), maths.exp(maths.dotMultiply(q, -1*(this.z2+z))));
fork icon2
star icon3
watch icon0

34
35
36
37
38
39
40
41
42
43

// arithmetic
math.add(a, b); // add
math.cube(a); // cube
math.cbrt(8); // cube root
math.divide(a, b); // divide
math.exp(8) // exponent (e ** x)
math.log(a) // ln
math.log(a, 2) // log base 2
math.mod(a, b) // modulus (remainder)
fork icon0
star icon3
watch icon0

+ 6 other calls in file

1108
1109
1110
1111
1112
1113
1114
1115
1116
    }

    this.#values = this.#applyPrecision(dividedValues, this.#precision);

    if (signal.units.values != "-") {
        let dividedUnit = mathjs.divide(mathjs.unit(this.units.values), mathjs.unit(signal.units.values));
        this.#units.values = dividedUnit.toString();
    }
}
fork icon0
star icon3
watch icon0

+ 3 other calls in file

3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
    return 1 / (1 + Math.exp(-z));
}


function sigmoidMatrix(m) {
    //Assumes input to be an N x 1 matrix
    return math.divide(1, math.add(1, math.map(math.exp, math.subtract(0,m))));
}


function AI(seed, mutate) {
    if (seed) {
fork icon1
star icon2
watch icon0

+ 6 other calls in file

165
166
167
168
169
170
171
172
173
174
    gamma = gamma_t
}

var D = math.flatten(math.multiply(-2, math.subtract(high_config.points, low_config.points)))
var h_grad = math.flatten(high_config.status.energy_grad)
var G = math.divide(h_grad, math.norm(h_grad))
if (edge_constrains_pairs.length === 0) {
    update_config_naive(high_config, D, G, learning_rate)
} else {
    gamma = update_config_with_constrains(high_config, length_const, D, G,
fork icon1
star icon1
watch icon7

33
34
35
36
37
38
39
40
41
42
* @param {Number} M - Number of partitions to calculate the integral.
    * @return {Number|BigNumber} integral - Result of the integral by the compose trapezium rule
    * */
   
   trapezoidalRule : function(f, a, b, M) {
           var h = math.divide(math.add(b, -a), M);
           var sum = 0;
           for(var k = 1; k < M; ++k) {
                   var x = math.add(a, math.multiply(h, k));
                   sum = math.add(sum, f(x));
fork icon0
star icon1
watch icon13

+ 51 other calls in file

18
19
20
21
22
23
24
25
26
27
linspace: function(start, end, n, inclusive) {
    //Set defaults
    n = n || 50;
    inclusive = inclusive !== undefined ? inclusive : true;

    var step = math.divide(math.subtract(end, start), inclusive ? n-1 : n);
    var result = new Array(n);
    for (var i = 0; i < n; ++i) {
        result[i] = start + i * step;
    }
fork icon1
star icon0
watch icon15

46
47
48
49
50
51
52
53
54
55
let { maxLeverage } = await bybit.getIncrements(symbol)
let params = await this.getLastParam(symbol, timeframes[interval], 120)
if(params.status){
    let elementPrice = params[element]
    if(condition == "below"){
        if(smallerEq(parseFloat(lastPrice), add(parseFloat(elementPrice), divide(multiply(parseFloat(buffer), parseFloat(elementPrice)), 100)))){
            await Ichimoku.findByIdAndDelete(_id)
            let positionInfo = await kline.calculatePositionParameters(symbol, "buy")
            let { callbackRate, stopLossStopPrice, stopLossLimitPrice, activationPrice, highPercent, lowPercent, longR2R, shortR2R } = positionInfo
            console.log(`${symbol} is ${condition} ${element} ${timeframes[interval]} price: ${lastPrice} buffer: ${buffer} ${type}\n stop:${stopLossStopPrice}, limit: ${stopLossLimitPrice}, activationPrice: ${activationPrice} callbackRate: ${callbackRate} low: ${lowPercent} shortR2R: ${longR2R}`)
fork icon1
star icon0
watch icon0

+ 7 other calls in file

437
438
439
440
441
442
443
444
445
446
447


exports.setTrailingStop = async (symbol, side, callbackRate) => {
    let { pricePercision } = await this.getIncrements(symbol)
    let { lastPrice } = await this.getLastPrice(symbol)
    let callbackPrice;
    callbackPrice = divide(multiply(lastPrice, callbackRate), 100).toFixed(pricePercision)
    let params = {
        side, symbol, trailing_stop: callbackPrice,       
        timestamp: Date.now().toString(),
        api_key : apiKey,
fork icon1
star icon0
watch icon0

+ 3 other calls in file

17
18
19
20
21
22
23
24
25
26
exports.closeType = async ({oArray, cArray, hArray, lArray}) => {
    let closeType = [], bodyPercentArray=[], highShadowPercentArray=[], lowShadowPercentArray=[], klineDistance, bodyDistance, highShadowDistance, lowShadowDistance, bodyPercent, highShadowPercent, lowShadowPercent;
    let step;
    cArray.forEach((close, index) => {
        let klineDistance = subtract(hArray[index], lArray[index])
            step = divide(klineDistance, 3);
            if(largerEq(close, lArray[index]) && smaller(close, add(lArray[index], step))){
                closeType.push("lowClose")
            }else if(largerEq(close, add(lArray[index], step)) && smaller(close, subtract(hArray[index], step))){
                closeType.push("midClose")
fork icon1
star icon0
watch icon0

+ 35 other calls in file

14
15
16
17
18
19
20
21
22
23
math.config(config);

const bignumber = math.bignumber;
const matrix = math.matrix;

//const TRIANGLE_UNIT_HEIGHT = math.divide(math.sqrt(bignumber("3")), bignumber("2"));

const GRADIENTS = {
    major_diag: math.tan(math.unit(120, "deg")),
    anti_diag: math.tan(math.unit(-120, "deg")),
fork icon1
star icon0
watch icon1

+ 3 other calls in file

185
186
187
188
189
190
191
192
193
194
    // console.log(this.finalChargeIdentical.toString())
}

getElectricForceMagnitudeBefore() {
    // F_{e} = k\\frac{\\abs{q_{1}q_{2}}}{r^{2}}
    this.electricForceMagnitudeBefore = (multiply(this.coulombConstant, divide(abs(multiply(this.parsedCharges[0].convertedUnitCharge, this.parsedCharges[1].convertedUnitCharge)), square(this.distance)))).to('N')
    this.electricForceMagnitudeBeforeLatex = `F_{e} = k\\frac{| q_{1}q_{2} |}{r^{2}} \\rightarrow ${this.coulombConstant.toString()}\\frac{|${this.parsedCharges[0].convertedUnitCharge.toString()}\\times${this.parsedCharges[1].convertedUnitCharge.toString()}|}{(${this.distance.toString()})^{2}} = \`${this.electricForceMagnitudeBefore.toString()}\``
    // console.log(this.electricForceMagnitudeBefore.to('N').toString())
    // console.log(this.electricForceMagnitudeBeforeLatex)
}
fork icon0
star icon1
watch icon0

+ 2 other calls in file

44
45
46
47
48
49
50
51
52
53
this.height.actual = divide(subtract(square(this.finalVelocity.actual), square(this.initialVelocity.actual)), multiply(2, gravity));
this.height.rounded = clone(this.height.actual);
this.height.rounded.value = SigFig(this.height.rounded.value, this.roundToSigFig) 
this.equationInLatex.push(`d = \\frac{{v_{f}}^{2} - {v_{i}}^{2}}{2g} \\implies \\frac{(${this.finalVelocity.actual.toString()})^{2} - (${this.initialVelocity.actual.toString()})^{2}}{2(${gravity.toString()})} = ${this.height.rounded.toString()}`)
// Find the time use the formula t = vf - vi / g
this.time.actual = divide(subtract(this.finalVelocity.actual, this.initialVelocity.actual), gravity);
this.time.rounded = clone(this.time.actual);
this.time.rounded.value = SigFig(this.time.rounded.value, this.roundToSigFig) 
this.equationInLatex.push(`t = \\frac{v_{f} - v_{i}}{g} \\implies \\frac{${this.finalVelocity.actual.toString()} - ${this.initialVelocity.actual.toString()}}{${gravity.toString()}} = ${this.time.rounded.toString()}`)
this.givenInfo = `
fork icon0
star icon1
watch icon0

+ 10 other calls in file