Skip to content

Commit

Permalink
added separators
Browse files Browse the repository at this point in the history
  • Loading branch information
fibo committed Feb 3, 2013
1 parent aaaa70a commit 2d82422
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 7 deletions.
61 changes: 54 additions & 7 deletions lib/Real/Element.js
Expand Up @@ -2,14 +2,19 @@
function RealElement(arg) {
var self = this;

//-----------------------------------------------------------------------------

var _num = 0;
if (typeof arg == 'number') {
_num = arg;
}

self.num = function () { return _num; };

function coerce(x) {

//-----------------------------------------------------------------------------

function _coerce(x) {
if (typeof x == 'number') {
return x;
}
Expand All @@ -18,95 +23,137 @@ function RealElement(arg) {
}
};


//-----------------------------------------------------------------------------

function equals(x) {
var num = coerce(x);
var num = _coerce(x);

return (num == _num);
};

self.eq = self.equals = equals;


//-----------------------------------------------------------------------------

function notEquals(x) {
var num = coerce(x);
var num = _coerce(x);

return (num != _num);
};

self.ne = self.notEquals = notEquals;


//-----------------------------------------------------------------------------

function isZero() {
return equals(0);
};

self.isZero = isZero;


//-----------------------------------------------------------------------------

function isOne() {
return equals(1);
};

self.isOne = isOne;


//-----------------------------------------------------------------------------

function isNotZero() {
return notEquals(0);
};

self.isNotZero = isNotZero;


//-----------------------------------------------------------------------------

self.neg = function () {
_num = 0 - _num;

return self;
};


//-----------------------------------------------------------------------------

self.add = function (x) {
var num = coerce(x);
var num = _coerce(x);

_num += num;

return self;
};


//-----------------------------------------------------------------------------

self.sub = function (x) {
var num = coerce(x);
var num = _coerce(x);

_num -= num;

return self;
};


//-----------------------------------------------------------------------------

self.inv = function () {
_num = 1 / _num;

return self;
};


//-----------------------------------------------------------------------------

self.mul = function (x) {
var num = coerce(x);
var num = _coerce(x);

_num *= num;

return self;
};


//-----------------------------------------------------------------------------

self.div = function (x) {
var num = coerce(x);
var num = _coerce(x);

_num /= num;

return self;
};


//-----------------------------------------------------------------------------

self.exp = function () {
_num = Math.exp(_num);

return self;
};


//-----------------------------------------------------------------------------

self.log = function () {
_num = Math.log(_num);

return self;
};

//-----------------------------------------------------------------------------

};

RealElement.prototype.clone = function () {
Expand Down
12 changes: 12 additions & 0 deletions lib/Real/Field.js
Expand Up @@ -11,15 +11,27 @@ function RealField() {

util.inherits(RealField, Field);


//-----------------------------------------------------------------------------

RealField.prototype.coerceToElement = coerce.toRealElement;


//-----------------------------------------------------------------------------

function getZero() { return new RealElement(0); };

RealField.prototype.getZero = getZero;


//-----------------------------------------------------------------------------

function getOne() { return new RealElement(1); };

RealField.prototype.getOne = getOne;


//-----------------------------------------------------------------------------

module.exports = RealField;

7 changes: 7 additions & 0 deletions lib/Real/Vector.js
Expand Up @@ -8,10 +8,14 @@ function RealVector(arg) {

Vector.call(self, arg);

//-----------------------------------------------------------------------------

self.x = function (i) {
return self.getElement(i).num();
};

//-----------------------------------------------------------------------------

self.getCoordinates = function () {
var coordinates = [];

Expand All @@ -21,6 +25,9 @@ function RealVector(arg) {

return coordinates;
};

//-----------------------------------------------------------------------------

};

util.inherits(RealVector, Vector);
Expand Down
6 changes: 6 additions & 0 deletions lib/Real/VectorSpace.js
Expand Up @@ -16,6 +16,9 @@ function RealVectorSpace(dim) {

VectorSpace.call(self, arg);


//-----------------------------------------------------------------------------

self.Vector = function Vector() {
var arg = {};
arg.elements = [];
Expand All @@ -29,6 +32,9 @@ function RealVectorSpace(dim) {

RealVector.call(this, arg);
};

//-----------------------------------------------------------------------------

}

RealVectorSpace.prototype = VectorSpace.prototype;
Expand Down

0 comments on commit 2d82422

Please sign in to comment.