Skip to content

RealField

fibo edited this page · 6 revisions

Real Field

source

Constructor

var algebra = require('algebra');

var Field     = algebra.Field;
var Real      = algebra.Real.Element;
var RealField = algebra.Real.Field;

var R = new RealField();

Inheritance

Is a Field

Implements

coerceToElement()

  var x = R.coerceToElement(1);
  console.log(x instanceof Real); // true

Methods

getZero()

Returns the zero element.

  console.log(R.getZero().num()); // 0

getOne()

Returns the one element.

  console.log(R.getOne().num()); // 1

eq(number|Real, number|Real)

Returns true if two elements are equal.

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

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

Coerces number type.

  var x = new Real(-1);
  console.log(R.eq(x, -1));  // true
  console.log(R.eq(-1, x));  // true
  console.log(R.eq(-1, -1)); // true

neg(number|Real)

Returns the inverse by addition.

  var x = new Real(2);
  var y = R.neg(x);
  console.log(y.num()); // -2

Coerces number type.

  var x = 5;
  var y = R.neg(x);
  console.log(y.num()); // -5

add(number|Real, number|Real)

Returns the result of addition.

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

  var z = R.add(x, y)

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

Coerces number type.

  var x = R.add(2, 5);
  console.log(x.num()); // 7

sub(number|Real, number|Real)

Returns the result of subtraction.

  var x = new Real(1);
  var y = new Real(2);

  var z = R.sub(x, y)

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

Coerces number type.

  var x = R.sub(2, 5);
  console.log(x.num()); // -3

inv(number|Real)

Returns the inverse by multiplication.

  var x = new Real(-2);
  var y = R.inv(x);
  console.log(y.num()); // -0.5

Coerces number type.

  var x = R.inv(4);
  console.log(x.num()); // 0.25

mul(number|Real, number|Real)

Implements the multiplication operator.

  var x = new Real(2);
  var y = new Real(5);
  var z = R.mul(x, y);
  console.log(z.num()); // 10

Coerces number type.

  var x = R.mul(2, 5);
  console.log(x.num()); // 10

div(number|Real, number|Real)

Implements the division operator.

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

  var z = R.div(x, y);

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

Coerces number type.

  var x = new Real(15);

  var y = R.div(x, 3);
  console.log(y.num()); // 5

  var z = R.div(30, x);
  console.log(z.num()); // 2
Something went wrong with that request. Please try again.