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)
})
fork icon15
star icon149
watch icon9

+ 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));   
fork icon19
star icon29
watch icon6

+ 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));
fork icon8
star icon29
watch icon3

+ 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
fork icon8
star icon28
watch icon3

+ 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
fork icon8
star icon28
watch icon3

+ 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') {
fork icon8
star icon28
watch icon3

+ 265 other calls in file

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)
        );
},
fork icon7
star icon16
watch icon0

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
fork icon0
star icon5
watch icon1

+ 3 other calls in file

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
fork icon0
star icon3
watch icon0

+ 13 other calls in file

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;
fork icon0
star icon1
watch icon1

+ 7 other calls in file

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]));
fork icon0
star icon0
watch icon0

+ 2 other calls in file