How to use the number function from mathjs

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

17
18
19
20
21
22
23
24
25
26
const sumOrderTotal = (orders) =>
    orders.reduce(
        (total, [price, size]) =>
            math.add(
                total,
                math.number(math.multiply(math.fraction(size), math.fraction(price)))
            ),
        0
    );

fork icon211
star icon236
watch icon0

+ 3 other calls in file

89
90
91
92
93
94
95
96
97
98
99
100
101
	return res;
}


const getUserQuickTrade = async (spending_currency, spending_amount, receiving_amount, receiving_currency, bearerToken, ip, opts) => {


	if (spending_amount) spending_amount = math.number(spending_amount);
	if (receiving_amount) receiving_amount = math.number(receiving_amount);


	const originalPair = `${spending_currency}-${receiving_currency}`;
	const flippedPair = `${receiving_currency}-${spending_currency}`;
fork icon206
star icon234
watch icon14

+ 9 other calls in file

59
60
61
62
63
64
65
66
67
68
}
if (math.typeof(evaluated[0]) == 'Unit') {
    //math.autoscale(evaluated);
    unit = '   [' + evaluated[0].toJSON().unit + ']';
    evaluated = _.map(evaluated,function(ev){
    return math.number(ev,ev.toJSON().unit);
  });

}
if (math.typeof(evaluated) == 'Unit') {
fork icon23
star icon77
watch icon11

+ 11 other calls in file

21
22
23
24
25
26
27
28
29
30
  attrExtractor (attrName) {
    return obj => obj[attrName]
  },

  add (a, b) {
    return math.number(math.add(math.bignumber(a), math.bignumber(b)))
  }
}
InviziLambda.sumFromObj = R.compose(R.reduce(InviziLambda.add, 0), R.values, R.map)
InviziLambda.sumArray = R.compose(R.reduce(InviziLambda.add, 0), R.map)
fork icon19
star icon62
watch icon5

+ 3 other calls in file

83
84
85
86
87
88
89
90
91
92


export function matrix_nul(mat: math.Matrix) {
  let reduced: math.Matrix = gauss_elimination(mat);
  reduced = reduced.map(function (value) {
    return math.number(value);
  });
  let free_variables: number[] = [];
  let free_variable_count: number = 0;
  // initlize loop and determine location of free variables
fork icon0
star icon5
watch icon2

72
73
74
75
76
77
78
79
80
81
    let initialX = math.number(ctx[variable]);

    ctx[variable] = initialX - DERIVATIVE_H;
    let f1 = math.number(math.eval(expression.toString(), ctx));
    ctx[variable] = initialX + DERIVATIVE_H;
    let f2 = math.number(math.eval(expression.toString(), ctx));

    return (f2 - f1) / (2 * DERIVATIVE_H);
}
throw new Error('Function ' + expression + '  is not supported by derivative, or a wrong number of arguments is passed');
fork icon0
star icon0
watch icon5

+ 111 other calls in file

194
195
196
197
198
199
200
201
202
203
},
binomialpdf: function (trials, probSuccess, x) {
    /* @help Probability of getting exactly x successes in a binomial setting */
    /* Normalize numbers */
    x = math.number(x);
    trials = math.number(trials);
    probSuccess = math.number(probSuccess);

    if (probSuccess <= 0 || probSuccess > 1)
        throw new RangeError('0 < probSuccess < 1 must be true');
fork icon0
star icon0
watch icon5

+ 113 other calls in file

122
123
124
125
126
127
128
129
130
131
        answer = math.multiply(valueL, valueR)
    } else if (this instanceof DivideBy) {
        answer = math.divide(valueL, valueR)
    }

    return this.answerFormat === 'ratio' ? answer : math.number(answer)
}

#getWrongAnswer(answer) {
    let wrongAnswer, offset
fork icon0
star icon0
watch icon0

544
545
546
547
548
549
550
551
552
553
	'toolsLib/wallet/withdrawalBelowLimit',
	`total 24 hour ${currency} withdrawn amount`,
	last24HourWithdrawalAmount
);

let totalWithdrawalAmount = math.number(
	math.add(
		math.bignumber(amount),
		math.bignumber(last24HourWithdrawalAmount)
	)
fork icon0
star icon0
watch icon1

+ 365 other calls in file