Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

RealElement

fibo edited this page · 12 revisions

Real Element

source

Constructor

var algebra = require('algebra');

var RealElement = algebra.Real.Element;

Accepts a number as single argument.

var ten = new RealElement(10);

Inheritance

Is a RingElement.

Methods

clone()

Returns a copy of the object.

var x = new RealElement(-15);
var y = x.clone();

num()

Returns the real number.

var x = new RealElement(2.71);
console.log(x.num()); // 2.71

equals()

Returns true if two elements are equal.

var x = new RealElement(-1);
var y = new RealElement(-1);

console.log(x.eq(y)); // true
console.log(y.eq(x)); // true

Corces number type.

var x = new RealElement(-1);
console.log((x.eq(-1)); // true

Has reflection property.

console.log(x.eq(x)); // true

eq()

It is an alias of equals().

notEquals()

Returns true if two elements are not equal.

var x = new RealElement(-1);
var y = new RealElement(-2);

console.log(x.notEquals(y)); // true
console.log(y.notEquals(x)); // true

y.add(1);
console.log(x.notEquals(y)); // false

Corces number type.

var x = new RealElement(-1);
console.log((x.eq(-1)); // true

ne()

It is an alias of notEquals().

isZero()

Returns true if element is zero.

var x = new RealElement(0);
console.log(x.isZero()); // true

isOne()

Returns true if element is one.

var x = new RealElement(1);
console.log(x.isOne()); // true

isNotZero()

Returns true if element is not zero.

var x = new RealElement(10);
console.log(x.isNotZero()); // true

x.mul(0);
console.log(x.isNotZero()); // false

neg()

Implements inversion by addition operator.

var x = new RealElement(4);
var y = x.clone();

y.neg();

console.log(x.add(y).isZero()); // true

Can be chained.

add(number|RealElement)

Implements the addition operator.

var x = new RealElement(2);
var y = new RealElement(3);

x.add(y);

console.log(x.num()); // 5

sub(number|RealElement)

Implements the subtraction operator.

var x = new RealElement(2);
var y = new RealElement(3);

x.sub(y);

console.log(x.num()); // -1

Coerces number type.

var x = new RealElement(20);

x.sub(3);

console.log(x.num()) // 17

Can be chained.

inv()

Implements inversion by multiplication operator.

var x = new RealElement(-2);
var y = x.clone();

y.inv();

console.log(x.mul(y).isOne()); // true

Can be chained.

mul(number|RealElement)

Implements the multiplication operator.

var x = new RealElement(2);
var y = new RealElement(3);

x.mul(y);

console.log(x.num()); // 6

Coerces number type.

var x = new RealElement(2);

x.mul(3);

console.log(x.num()) // 6

Can be chained.

div(number|RealElement)

Implements the division operator.

var x = new RealElement(20);
var y = new RealElement(4);

x.div(y);

console.log(x.num()); // 5

Coerces number type.

var x = new RealElement(15);

x.div(3);

console.log(x.num()) // 5

Can be chained.

exp()

Implements the exponential function.

var x = new RealElement(0);

x.exp();

console.log(x.num()); // 1

Can be chained.

log()

Implements the real logarithm function.

var x = new RealElement(1);

x.log();

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

Can be chained.

Something went wrong with that request. Please try again.