Skip to content

Commit

Permalink
added exp and log
Browse files Browse the repository at this point in the history
  • Loading branch information
fibo committed Jan 10, 2013
1 parent 70a6e80 commit 9987dcb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
12 changes: 12 additions & 0 deletions lib/Real/Element.js
Expand Up @@ -75,6 +75,18 @@ var RealElement = function (arg) {

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
33 changes: 25 additions & 8 deletions test/Real/Element.js
Expand Up @@ -199,18 +199,35 @@ describe('RealElement', function () {

assert.equal(x.num(), 1);
});
});

describe('exp()', function () {
it('implements the exponential function', function () {
var x = new Real(0);

x.exp();

it('TODO division by 0 (in realta 1/0 fa Infinity)', function () {
// TODO siccome poi lo zero c'è in tutti i campi e non ci sono zero divisori (credo) nei campi, ci possono essere solo negli anelli, allora se faccio diviso zero deve lanciare un' eccezione
//
// Anche se ho Infinity, ma in algebra non va bene
//
// se voglio anche infinity devo usare una classe diversa , tipo R*, o la posso chaimare RealFieldPlus o RealFieldPlusInfinity
assert.equal(x.num(), 1);
});

it('can be chained', function () {
var x = new Real(2);
assert.ok(x.exp() instanceof Real);
});
});

describe('toString()', function () {
it('...', function () {
describe('log()', function () {
it('implements the real logarithm', function () {
var x = new Real(1);

x.log();

assert.equal(x.num(), 0);
});

it('can be chained', function () {
var x1 = new Real(2);
assert.ok(x1.log() instanceof Real);
});
});
});
Expand Down

0 comments on commit 9987dcb

Please sign in to comment.