### XFloat Documentation - 3. Basic Operations

- Top: XFloat Documentation

## 3. Basic Operations

### Constructor

#### new XFloat()

Create a new XFloat object. The initial value is set to zero.

#### new XFloat(number[, exponent])

- number: (24-bit integer or real number) the initial mantissa value
- exponent: (24-bit integer) the initial exponent value. when it is omitted, it is considered as 0

Create a new XFloat object. The initial value is set to number * B

^{exponent}. B is 2^{24}.#### new XFloat(xf)

- xf: (XFloat object) object to create a copy

Create a new XFloat object with a copy of xf.

#### new XFloat(str)

- str: (String) string representing decimal number

Create a new XFloat object with the value of str. str should be representation of decimal numbers.

In the process of converting a str expressed in decimal to binary, an error will occur. When you create an object XFloat through this method, the precision of conversion is adjusted to the number of significant digits in str. That rate is the one word to approximately 7 decimal places.

#### Constructor Example

### Arithmetic

#### .add(xf)

- xf: (XFloat object) the value to add

Add xf to current object.

This method returns 'this'.

#### .add(number[, exponent])

- number: (24bit integer) the mantissa of value to add
- exponent: (24bit integer) the exponent of value to add, when it is omitted, it is considered as 0

Add number * B

^{exponent}to current object. B is 2^{24}.This method returns 'this'.

#### .sub(xf)

- xf: (XFloat objbect) the value to subtract

Subtract xf from current object.

This method returns 'this'.

#### .sub(number[, exponent])

- number: (24bit integer) the mantissa of value to subtract
- exponent: (24bit integer) the exponent of value to subtract, when it is omitted, it is considered as 0

Subtract number * B

^{exponent}from current object. B is 2^{24}.This method returns 'this'.

#### .mul(a, b)

- a: (XFloat object or 24bit integer) the value to multiply
- b: (XFloat object or 24bit integer) the value to multiply

Store the value of multiplication of aand b in current object. Either a or b can be XFloat object or 24bit integer, but both a and b cannot be 24bit integers.

This method returns 'this'.

#### .div(a, b)

- a: (XFloat object) the value to be divided
- b: (XFloat objector 24bit integer) the value to divide

Store the quotient of a divided by b in current object. The rest of division is stored in a. If b is 0, XFloatError is occurred. This method calculates q and r, meeting a = bq + r. q should be integer, and 0 <= r < |b| if a is positive, -|b| < r <= 0 if a is negative, and r = 0 if a is 0. You cannot calculate a fraction of the quotient like 1/3 = 0.333... If you want fraction part of the quotient, use inv method

This method changes the value of a. If you need the value before changing, you should make a copy of it ahead.

This method returns 'this'.

#### .neg()

Negate the sign of current object.

This method returns 'this'.

All of arithmetic method returns 'this'. So you can chain operations like a.add(b).sub(c).