Updated examples

This commit is contained in:
jos 2015-11-10 21:11:37 +01:00
parent 2223407b54
commit 109072ecbf
16 changed files with 70 additions and 72 deletions

View File

@ -14,7 +14,7 @@
}
</style>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.0/math.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.1/math.min.js"></script>
</head>
<body>
@ -58,37 +58,32 @@
['sin', 'cos', 'tan', 'sec', 'cot', 'csc'].forEach(function(name) {
var fn = math[name]; // the original function
replacements[name] = function replacement(x) {
if (x instanceof math.type.BigNumber) {
x = x.toNumber(); // convert to number
var fnNumber = function (x) {
// convert from configured type of angles to radians
switch (config.angles) {
case 'deg':
return fn(x / 360 * 2 * Math.PI);
case 'grad':
return fn(x / 400 * 2 * Math.PI);
default:
return fn(x);
}
if (typeof x === 'boolean') {
x = +x; // convert to number
}
if (typeof x === 'number') {
// convert from configured type of angles to radians
switch(config.angles) {
case 'deg': return fn(x / 360 * 2 * Math.PI);
case 'grad': return fn(x / 400 * 2 * Math.PI);
default: return fn(x);
}
}
if (math.collection.isCollection(x)) {
return math.collection.deepMap(x, replacement);
}
return fn(x);
};
// create a typed-function which check the input types
replacements[name] = math.typed(name, {
'number': fnNumber,
'Array | Matrix': function (x) {
return math.map(x, fnNumber);
}
});
});
// create trigonometric functions replacing the output depending on angle config
['asin', 'acos', 'atan', 'atan2'].forEach(function(name) {
['asin', 'acos', 'atan', 'atan2', 'acot', 'acsc', 'asec'].forEach(function(name) {
var fn = math[name]; // the original function
replacements[name] = function replacement(x) {
var fnNumber = function (x) {
var result = fn(x);
if (typeof result === 'number') {
@ -100,12 +95,16 @@
}
}
if (math.collection.isCollection(x)) {
return math.collection.deepMap(x, replacement);
}
return result;
};
// create a typed-function which check the input types
replacements[name] = math.typed(name, {
'number': fnNumber,
'Array | Matrix': function (x) {
return math.map(x, fnNumber);
}
});
});
// import all replacements into math.js, override existing trigonometric functions

View File

@ -23,7 +23,7 @@ File: [angle_configuration.html](angle_configuration.html)
}
</style>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.0/math.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.1/math.min.js"></script>
</head>
<body>
@ -67,37 +67,32 @@ File: [angle_configuration.html](angle_configuration.html)
['sin', 'cos', 'tan', 'sec', 'cot', 'csc'].forEach(function(name) {
var fn = math[name]; // the original function
replacements[name] = function replacement(x) {
if (x instanceof math.type.BigNumber) {
x = x.toNumber(); // convert to number
var fnNumber = function (x) {
// convert from configured type of angles to radians
switch (config.angles) {
case 'deg':
return fn(x / 360 * 2 * Math.PI);
case 'grad':
return fn(x / 400 * 2 * Math.PI);
default:
return fn(x);
}
if (typeof x === 'boolean') {
x = +x; // convert to number
}
if (typeof x === 'number') {
// convert from configured type of angles to radians
switch(config.angles) {
case 'deg': return fn(x / 360 * 2 * Math.PI);
case 'grad': return fn(x / 400 * 2 * Math.PI);
default: return fn(x);
}
}
if (math.collection.isCollection(x)) {
return math.collection.deepMap(x, replacement);
}
return fn(x);
};
// create a typed-function which check the input types
replacements[name] = math.typed(name, {
'number': fnNumber,
'Array | Matrix': function (x) {
return math.map(x, fnNumber);
}
});
});
// create trigonometric functions replacing the output depending on angle config
['asin', 'acos', 'atan', 'atan2'].forEach(function(name) {
['asin', 'acos', 'atan', 'atan2', 'acot', 'acsc', 'asec'].forEach(function(name) {
var fn = math[name]; // the original function
replacements[name] = function replacement(x) {
var fnNumber = function (x) {
var result = fn(x);
if (typeof result === 'number') {
@ -109,12 +104,16 @@ File: [angle_configuration.html](angle_configuration.html)
}
}
if (math.collection.isCollection(x)) {
return math.collection.deepMap(x, replacement);
}
return result;
};
// create a typed-function which check the input types
replacements[name] = math.typed(name, {
'number': fnNumber,
'Array | Matrix': function (x) {
return math.map(x, fnNumber);
}
});
});
// import all replacements into math.js, override existing trigonometric functions

View File

@ -2,7 +2,7 @@
<html>
<head>
<title>math.js | basic usage</title>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.0/math.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.1/math.min.js"></script>
</head>
<body>

View File

@ -11,7 +11,7 @@ File: [basic_usage.html](basic_usage.html)
<html>
<head>
<title>math.js | basic usage</title>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.0/math.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.1/math.min.js"></script>
</head>
<body>

View File

@ -14,7 +14,7 @@
}
</style>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.0/math.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.1/math.min.js"></script>
</head>
<body>

View File

@ -23,7 +23,7 @@ File: [custom_separators.html](custom_separators.html)
}
</style>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.0/math.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.1/math.min.js"></script>
</head>
<body>

View File

@ -7,7 +7,7 @@
<script src="//cdnjs.cloudflare.com/ajax/libs/es5-shim/2.2.0/es5-shim.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/es5-shim/2.2.0/es5-sham.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.0/math.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.1/math.min.js"></script>
</head>
<body>

View File

@ -16,7 +16,7 @@ File: [old_browsers.html](old_browsers.html)
<script src="//cdnjs.cloudflare.com/ajax/libs/es5-shim/2.2.0/es5-shim.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/es5-shim/2.2.0/es5-sham.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.0/math.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.1/math.min.js"></script>
</head>
<body>

View File

@ -2,7 +2,7 @@
<html>
<head>
<title>math.js | plot</title>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.0/math.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.1/math.min.js"></script>
<!-- load http://maurizzzio.github.io/function-plot/ -->
<script src="http://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>

View File

@ -11,7 +11,7 @@ File: [plot.html](plot.html)
<html>
<head>
<title>math.js | plot</title>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.0/math.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.1/math.min.js"></script>
<!-- load http://maurizzzio.github.io/function-plot/ -->
<script src="http://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>

View File

@ -3,7 +3,7 @@
<head>
<title>math.js | pretty printing with MathJax</title>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.0/math.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.1/math.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjax/2.3/MathJax.js?config=TeX-AMS-MML_HTMLorMML.js"></script>
<style>

View File

@ -12,7 +12,7 @@ File: [pretty_printing_with_mathjax.html](pretty_printing_with_mathjax.html)
<head>
<title>math.js | pretty printing with MathJax</title>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.0/math.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.1/math.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjax/2.3/MathJax.js?config=TeX-AMS-MML_HTMLorMML.js"></script>
<style>

View File

@ -8,7 +8,7 @@
<script>
// load math.js using require.js
require(['http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.0/math.min.js'], function (math) {
require(['http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.1/math.min.js'], function (math) {
// evaluate some expression
var result = math.eval('1.2 * (2 + 4.5)');
document.write(result);

View File

@ -17,7 +17,7 @@ File: [requirejs_loading.html](requirejs_loading.html)
<script>
// load math.js using require.js
require(['http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.0/math.min.js'], function (math) {
require(['http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.1/math.min.js'], function (math) {
// evaluate some expression
var result = math.eval('1.2 * (2 + 4.5)');
document.write(result);

View File

@ -91,7 +91,7 @@ File: [webworkers.html](webworkers.html)
File: [worker.js](worker.js)
```js
importScripts('http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.0/math.min.js');
importScripts('http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.1/math.min.js');
// create a parser
var parser = math.parser();

View File

@ -1,4 +1,4 @@
importScripts('http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.0/math.min.js');
importScripts('http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.1/math.min.js');
// create a parser
var parser = math.parser();