Renamed function category "Comparison" with "Relational"

This commit is contained in:
jos 2014-07-20 12:40:34 +02:00
parent 21b34cfa1a
commit 59de16801e
33 changed files with 52 additions and 52 deletions

View File

@ -12,7 +12,7 @@ configure math.js:
The following configuration options are available:
- `epsilon`. The minimum relative difference used to test equality between two
compared values. This value is used by all comparison functions.
compared values. This value is used by all relational functions.
Default value is `1e-14`.
- `matrix`. The default type of matrix output for functions.

View File

@ -58,14 +58,14 @@ console.log(1e309); // Infinity
console.log(1e-324); // 0
```
## Comparison
## Equality
Because of rounding errors in calculations, it is unsafe to compare JavaScript
Numbers. For example executing `0.1 + 0.2 == 0.3` in JavaScript will return
false, as the addition `0.1 + 0.2` introduces a round-off error and does not
return exactly `0.3`.
To solve this problem, the comparison functions of math.js check whether the
To solve this problem, the relational functions of math.js check whether the
relative difference between the compared values is smaller than the configured
option `epsilon`. In pseudo code (without exceptions for 0, Infinity and NaN):
@ -80,7 +80,7 @@ where:
`1.0 + DBL_EPSILON != 1.0`. This is a constant with a value of approximately
`2.2204460492503130808472633361816e-16`;
Note that the comparison functions cannot be used to compare small values
Note that the relational functions cannot be used to compare small values
(`< 2.22e-16`). These values are all considered equal to zero.
Examples:
@ -95,5 +95,5 @@ console.log(3e-20 == 3.1e-20); // false
console.log(math.equal(3e-20, 3.1e-20)); // true
```
The available comparison functions are: `compare`, `equal`, `larger`,
The available relational functions are: `compare`, `equal`, `larger`,
`largerEq`, `smaller`, `smallerEq`, `unequal`.

View File

@ -305,7 +305,7 @@ Operators | Description
`x unit` | Unit
`*`, `/`, `.*`, `./`, `%`, `mod` | Multiply, divide, modulus, implicit multiply
`+`, `-` | Add, subtract
`==`, `!=`, `<`, `>`, `<=`, `>=` | Comparison
`==`, `!=`, `<`, `>`, `<=`, `>=` | Relational
`to`, `in` | Unit conversion
`:` | Range
`?`, `:` | Conditional expression

View File

@ -30,17 +30,6 @@
- [unaryPlus(x)](unaryPlus.md)
- [xgcd(a, b)](xgcd.md)
## comparison
- [compare(x, y)](compare.md)
- [deepEqual(x, y)](deepEqual.md)
- [equal(x, y)](equal.md)
- [larger(x, y)](larger.md)
- [largerEq(x, y)](largerEq.md)
- [smaller(x, y)](smaller.md)
- [smallerEq(x, y)](smallerEq.md)
- [unequal(x, y)](unequal.md)
## complex
- [arg(x)](arg.md)
@ -94,6 +83,17 @@
- [random([min, max])](random.md)
- [randomInt([min, max])](randomInt.md)
## relational
- [compare(x, y)](compare.md)
- [deepEqual(x, y)](deepEqual.md)
- [equal(x, y)](equal.md)
- [larger(x, y)](larger.md)
- [largerEq(x, y)](largerEq.md)
- [smaller(x, y)](smaller.md)
- [smallerEq(x, y)](smallerEq.md)
- [unequal(x, y)](unequal.md)
## statistics
- [max(a, b, c, ...)](max.md)

View File

@ -58,7 +58,7 @@ Parameter | Type | Description
Type | Description
---- | -----------
String | str The formatted value
String | The formatted value
## Examples

View File

@ -1,6 +1,6 @@
module.exports = {
'name': 'compare',
'category': 'Comparison',
'category': 'Relational',
'syntax': [
'compare(x, y)'
],

View File

@ -1,6 +1,6 @@
module.exports = {
'name': 'deepEqual',
'category': 'Comparison',
'category': 'Relational',
'syntax': [
'deepEqual(x, y)'
],

View File

@ -1,6 +1,6 @@
module.exports = {
'name': 'equal',
'category': 'Comparison',
'category': 'Relational',
'syntax': [
'x == y',
'equal(x, y)'

View File

@ -1,6 +1,6 @@
module.exports = {
'name': 'larger',
'category': 'Comparison',
'category': 'Relational',
'syntax': [
'x > y',
'larger(x, y)'

View File

@ -1,6 +1,6 @@
module.exports = {
'name': 'largerEq',
'category': 'Comparison',
'category': 'Relational',
'syntax': [
'x >= y',
'largerEq(x, y)'

View File

@ -1,6 +1,6 @@
module.exports = {
'name': 'smaller',
'category': 'Comparison',
'category': 'Relational',
'syntax': [
'x < y',
'smaller(x, y)'

View File

@ -1,6 +1,6 @@
module.exports = {
'name': 'smallerEq',
'category': 'Comparison',
'category': 'Relational',
'syntax': [
'x <= y',
'smallerEq(x, y)'

View File

@ -1,6 +1,6 @@
module.exports = {
'name': 'unequal',
'category': 'Comparison',
'category': 'Relational',
'syntax': [
'x != y',
'unequal(x, y)'

View File

@ -48,15 +48,15 @@ exports.unaryMinus = require('./function/arithmetic/unaryMinus');
exports.unaryPlus = require('./function/arithmetic/unaryPlus');
exports.xgcd = require('./function/arithmetic/xgcd');
// functions - comparison
exports.compare = require('./function/comparison/compare');
exports.deepEqual = require('./function/comparison/deepEqual');
exports['equal'] = require('./function/comparison/equal');
exports.larger = require('./function/comparison/larger');
exports.largerEq = require('./function/comparison/largerEq');
exports.smaller = require('./function/comparison/smaller');
exports.smallerEq = require('./function/comparison/smallerEq');
exports.unequal = require('./function/comparison/unequal');
// functions - relational
exports.compare = require('./function/relational/compare');
exports.deepEqual = require('./function/relational/deepEqual');
exports['equal'] = require('./function/relational/equal');
exports.larger = require('./function/relational/larger');
exports.largerEq = require('./function/relational/largerEq');
exports.smaller = require('./function/relational/smaller');
exports.smallerEq = require('./function/relational/smallerEq');
exports.unequal = require('./function/relational/unequal');
// functions - complex
exports.arg = require('./function/complex/arg');

View File

@ -542,7 +542,7 @@ function parseBitwiseConditions () {
var name = token;
getToken();
var params = [node, parseComparison()];
var params = [node, parseRelational()];
node = new OperatorNode(name, fn, params);
}
@ -603,7 +603,7 @@ function parseRange () {
function parseConditions () {
var node, operators, name, fn, params;
node = parseComparison();
node = parseRelational();
// TODO: precedence of And above Or?
// TODO: implement a method for unit to number conversion
@ -624,7 +624,7 @@ function parseConditions () {
fn = operators[name];
getToken();
params = [node, parseComparison()];
params = [node, parseRelational()];
node = new OperatorNode(name, fn, params);
}
@ -632,11 +632,11 @@ function parseConditions () {
}
/**
* comparison operators
* relational operators
* @return {Node} node
* @private
*/
function parseComparison () {
function parseRelational () {
var node, operators, name, fn, params;
node = parseAddSubtract();

View File

@ -194,15 +194,15 @@ function factory (config) {
require('./function/arithmetic/unaryPlus')(math, _config);
require('./function/arithmetic/xgcd')(math, _config);
// functions - comparison
require('./function/comparison/compare')(math, _config);
require('./function/comparison/deepEqual')(math, _config);
require('./function/comparison/equal')(math, _config);
require('./function/comparison/larger')(math, _config);
require('./function/comparison/largerEq')(math, _config);
require('./function/comparison/smaller')(math, _config);
require('./function/comparison/smallerEq')(math, _config);
require('./function/comparison/unequal')(math, _config);
// functions - relational
require('./function/relational/compare')(math, _config);
require('./function/relational/deepEqual')(math, _config);
require('./function/relational/equal')(math, _config);
require('./function/relational/larger')(math, _config);
require('./function/relational/largerEq')(math, _config);
require('./function/relational/smaller')(math, _config);
require('./function/relational/smallerEq')(math, _config);
require('./function/relational/unequal')(math, _config);
// functions - complex
require('./function/complex/arg')(math, _config);

View File

@ -906,7 +906,7 @@ describe('parse', function() {
assert.deepEqual(parseAndEval('false ? 1:2:6'), new Matrix([2,3,4,5,6]));
});
it('should respect precedence of comparison operator and conversion operators', function () {
it('should respect precedence of equal operator and conversion operators', function () {
var node = math.parse('a == b to c'); // (a == b) to c
assert.equal(node.op, 'to');
@ -914,7 +914,7 @@ describe('parse', function() {
assert.equal(node2.op, 'to');
});
it('should respect precedence of conditional operator and comparison operators', function () {
it('should respect precedence of conditional operator and relational operators', function () {
var node = math.parse('a == b ? a > b : a < b');
assert(node instanceof ConditionalNode);
assert.equal(node.condition.toString(), 'a == b');
@ -930,7 +930,7 @@ describe('parse', function() {
assert.equal(node.falseExpr.toString(), 'c:d');
});
it.skip('should respect precedence of range operator and comparison operators', function () {
it.skip('should respect precedence of range operator and relational operators', function () {
var node = math.parse('a:b == c:d');
assert(node instanceof OperatorNode);
assert.equal(node.params[0].toString(), 'a:b');