How to use the log function from mathjs
Find comprehensive JavaScript mathjs.log code examples handpicked from public code repositorys.
232 233 234 235 236 237 238 239 240 241
``` const mathjs = require('mathjs') test(`The mathjs log function`, () => { const spy = jest.spyOn(mathjs, 'log') const result = mathjs.log(10000, 10) expect(mathjs.log).toHaveBeenCalled() expect(mathjs.log).toHaveBeenCalledWith(10000, 10) })
15
149
9
+ 5 other calls in file
48 49 50 51 52 53 54 55 56 57
console.log(math.lcm(4, 6)); console.log(math.lcm(6, 21, 5)); console.log(math.lcm([4, 6], [6, 21])); // [12, 42] console.log(math.log(3.5)); // 1.252762968495368 console.log(math.log(10000, 10)); console.log(math.log(10000) / math.log(10)); console.log(math.log(1024, 2)); console.log(math.log10(0.00001)); console.log(math.log10(10000)); console.log(math.mod(8, 3));
19
29
6
+ 3 other calls in file
8 9 10 11 12 13 14 15 16 17
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; const cpow = math.pow; const csquare = z => cmul(z, z); const ccis = z => cexp(cmul_i(z));
8
29
3
+ 7 other calls in file
175 176 177 178 179 180 181 182 183 184 185
if (val.re === 0.5) {return ['sqrt', subAST];} if (val.re === 1) {return subAST;} if (val.re === 2) {return ['square', subAST];} // if (Number.isInteger(val.re)) {return ['rawpow', subAST, val.re];} // LOG_MODE only // return ['exp', ['component_mul', ['log', subAST], val.re]]; // Cartesian only return ['exp', ['component_mul_prelog', ['log', subAST], math.log(val.re)]]; // Cartesian only } } // return ['exp', ['mul', ['log', args[0]], args[1]]]; // Cartesian only
8
28
3
+ 509 other calls in file
174 175 176 177 178 179 180 181 182 183 184
if (val.re === 0) {return ['number', 1, 0];} if (val.re === 0.5) {return ['sqrt', subAST];} if (val.re === 1) {return subAST;} if (val.re === 2) {return ['square', subAST];} // return ['exp', ['component_mul', ['log', subAST], val.re]]; // Cartesian only return ['exp', ['component_mul_prelog', ['log', subAST], math.log(val.re)]]; // Log-cartesian only } } // return ['exp', ['mul', ['log', args[0]], args[1]]]; // Cartesian only
8
28
3
+ 89 other calls in file
187 188 189 190 191 192 193 194 195 196
if (operator === 'component_mul') { if (args[1] === 0 || isZero(args[0])) {return ['number', 0, 0];} if (args[1] > 0) { return ['component_mul_prelog', args[0], math.log(args[1])]; } else { return ['component_mul_prelog', compile(['neg', args[0]]), math.log(-args[1])]; } } if (operator === 'pow') {
8
28
3
+ 265 other calls in file
GitHub: kengz/Risk-game
118 119 120 121 122 123 124 125 126 127
// Logit, = inverse of logistic // ln[p/(1-p)], where p is normalized Logit: function(v) { var xscale = -1/6; function trans(x) { return xscale*x + 1; } function f(x) { return m.log( trans(x) / (1 - trans(x) ) ) + 6; } return fn.renorm( _.map(v, f) ); },
7
16
0
82 83 84 85 86 87 88 89 90
let base = 2, exp = 3, n = math.pow(base,exp); // 8 console.log( math.log(n,base) ); // 3 console.log( math.log(n,base) === exp ) // true ``` ## 4 - Big Numbers
0
5
1
+ 3 other calls in file
GitHub: jly36963/notes
36 37 38 39 40 41 42 43 44 45
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) math.multiply(a, b) // multiply math.pow(a, b) // a ** b
0
3
0
+ 13 other calls in file
GitHub: brin-eris/basic-bots
174 175 176 177 178 179 180 181 182 183
let exp = function(x){ let result = Mathjs.exp(x); return isNaN(result) ? 1.0 : result; } let log = function(x){ let result = Mathjs.log(x); return isNaN(result) ? 1.0 : result; } let cube = function(x){ return x*x*x;
0
1
1
+ 7 other calls in file
GitHub: Kirigaya-Kazuton/IA
61 62 63 64 65 66 67 68 69 70
// adição 3, 5 console.log('adição:', math.add([1, 2], [2, 3])); // divisão 5, 4 console.log('divisão:', math.dotDivide([10, 12], [2, 3])); // logaritmo console.log('logaritmo:', math.log([10, 12])); // logaritmo na base 2 console.log('logaritmo na base 2:', math.log2([10, 12])); // aproximação para baixo console.log('aproximação para baixo:', math.floor([1.2, 2.5, 3.9]));
0
0
0
+ 2 other calls in file
mathjs.evaluate is the most popular function in mathjs (87200 examples)