How to use the rationalize function from mathjs

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

21
22
23
24
25
26
27
28
29
30
31
32
33


mathjs.import({
  percent,
});


// const r = v => mathjs.rationalize(v);
// const a = mathjs.parse('4 x');
// const b = mathjs.parse('x 4');


const mo = (tree) => JSON.stringify(tree, null, '  ');
fork icon3
star icon4
watch icon0

22
23
24
25
26
27
28
29
30
31
case "ddx":
    try { done = await math.derivative(args.slice(1).join(" "), "x").compile().evaluate(); } catch(err) {done = "Differentiation Error"; NorthClient.storage.error(err);}
    break;
case "rationalize":
case "rat":
    try { done = math.rationalize(args.slice(1).join(" ")).toString(); } catch(err) {done = "Rationalization Error"; NorthClient.storage.error(err);}
    break;
case "simplify":
case "sim":
    try { done = math.simplify(args.slice(1).join(" ")).toString(); } catch(err) {done = "Simplification Error"; NorthClient.storage.error(err);}
fork icon1
star icon1
watch icon0

+ 3 other calls in file

62
63
64
65
66
67
68
69
70
var rationalize = 'rationalize';
var checkrationalize = args.indexOf(rationalize);

if(checkrationalize > -1) {
    args = args.substring((checkrationalize+rationalize.length));
    result = math.rationalize(args).toString();
}

if(!result) { result = math.evaluate(args).toString(); }
fork icon0
star icon1
watch icon0

561
562
563
564
565
566
567
568
569
570
571
 * @returns         If the number represented by a is close to the number represented by b
 */
helperNs.compareNumericalValues = function (a, b) {
    //try catch in place in case the fractions/decimals passed in aren't actually numbers
    try {
        a = math.rationalize(a).toString();
        b = math.rationalize(b).toString();


        //a or b aren't actual numerical values
        if (isNaN(a) || isNaN(b)) {
fork icon0
star icon0
watch icon0

+ 3 other calls in file

5
6
7
8
9
10
11
12
13
14
	try{
		var rs = rationalize(q);
	}catch(e){
		rs="No result";
	}
	//var rs = rationalize(q);
	res.render('hoplihoabieuthuc', {
		ketqua: rs
	});
}
fork icon0
star icon0
watch icon0

+ 3 other calls in file