Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
osofem authored Jul 4, 2017
1 parent c0b35b4 commit 25c5f7b
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 71 deletions.
17 changes: 13 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,17 @@
* change min() to accept any length of arguments

### v0.0.3
#### Released - 04th July, 2017
* Documentation update
* Fixed some bugs


### Planned to do!
* make max and min accept mixture of numbers and arrays e.g. max(1, 2, 3, [4, 5, 6])
* Added power
* Added sin()
* Added cos()
* Added tan()
* Add power()
* Add sin()
* Add cos()
* Add tan()
* Add log()
* Add log10()
* Improve squareRoot()
36 changes: 23 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Welcome to bigarith.js
[![Join the chat at https://gitter.im/BigArith-js/Lobby](https://badges.gitter.im/BigArith-js/Lobby.svg)](https://gitter.im/BigArith-js/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

`bigarith.js` offers a way to handles **very large numbers** (be it integers, fractionals, strings of digits, strings of english words) to precision. bigarith is from the words **big arith**metic.
`bigarith.js` offers a way to handle **very large numbers** (be it integers, fractionals, strings of digits, english words) to precision. bigarith is from the words **big arith**metic.

### Install
Depending on the environment in which bigarith.js will be used, it can be installed via:
Expand All @@ -14,7 +14,7 @@ Server-side usage

Client-side usage
1. Including the library from the rawgit.com CDN.<br>
You can do that by adding <code>&lt;script src=&quot;https&#58;&#47;&#47;cdn.rawgit.com/osofem/bigarith.js/&lt;version tag&gt;/bigarith.js&quot;&gt;&lt;/script&gt;</code> to your code. Replace <code>&lt;version tag&gt;</code> with the version targetted e.g. <code>v1.0.0</code>. Check [versions](https://github.com/osofem/bigarith.js/tags) for the latest version (the latest version is always recommended).
You can do that by adding `&lt;script src=&quot;https&#58;&#47;&#47;cdn.rawgit.com/osofem/bigarith.js/&lt;version tag&gt;/bigarith.js&quot;&gt;&lt;/script&gt;` to your code. Replace `&lt;version tag&gt;` with the version targeted e.g. `v1.0.0`. Check [versions](https://github.com/osofem/bigarith.js/tags) for the latest version (the latest version is always recommended).
2. Downloading the source from GitHub.com<br>
You can also download bigarith.js from [releases](https://github.com/osofem/bigarith.js/releases/) on github.com (the latest version is always recommended). Extract the files and include the bigarith.js file in your work.

Expand All @@ -23,7 +23,7 @@ Choose the method that best suit your need.
### Usage
`bigarith.js` can be initialized in six ways.

> In the server-side, always add the <code>var BigArith = require('bigarith.js');</code> and every other thing remains the same in both server-side and client-side.
> In the server-side, always add the `var BigArith = require('bigarith.js');` however every other thing remains the same in both server-side and client-side.
##### 1. Initiating without any parameter or null
###### Server-side
Expand All @@ -38,7 +38,7 @@ var ba = new BigArith(null); //initialize ba to a BigArith object of value "0"
var ba = new BigArith(); //initialize ba to a BigArith object of value "0"
var ba = new BigArith(null); //initialize ba to a BigArith object of value "0"
```
This simply initialize the variable <code>ba</code> to a `BigArith` object of value <code>"0"</code>.
This simply initialize the variable `ba` to a `BigArith` object of value `"0"`.

##### 2. Initiating with a number
###### Server-side
Expand All @@ -51,9 +51,9 @@ var ba = new BigArith(12345); //initialize ba to a BigArith object of value "123
```javascript
var ba = new BigArith(12345); //initialize ba to a BigArith object of value "12345"
```
The number must be between the <code>Number.MIN_SAFE_INTEGER</code> (-9007199254740991) and <code>Number.MAX_SAFE_INTEGER</code> (9007199254740991) limits else a <code>RangeError</code> will be thrown. <em>Please note that only integers are recommended for this method</em> because of the floating point precision _problem_ in JavaScript (with is one of the problems bigarith.js aim at solving).
The number must be between the `Number.MIN_SAFE_INTEGER` (-9007199254740991) and `Number.MAX_SAFE_INTEGER` (9007199254740991) limits else a `RangeError` will be thrown. <em>Please note that only integers are recommended for this method</em> because of the floating point precision _problem_ in JavaScript (which is one of the problems bigarith.js aim to solve).

Doing <code>var ba = new BigArith(0.45);</code> might still be considered _"safe"_ but some could be tempted to do <code>var ba = new BigArith(0.1\*0.2);</code>. As it is known <code>0.1\*0.2</code> will not give <code>0.02</code> in JavaScript but rather <code>0.020000000000000004</code>. Therefore, it is better to avoid initializing fractional numbers this way all together.
Doing `var ba = new BigArith(0.45);` might still be considered _"safe"_ but some could be tempted to do `var ba = new BigArith(0.1\*0.2);`. As it is known `0.1\*0.2` will not give `0.02` in JavaScript but rather `0.020000000000000004`. Therefore, it is better to avoid initializing fractional numbers this way.

> It is recommended fractional numbers are initialized with strings.
> See [here](#init_string).
Expand All @@ -77,8 +77,8 @@ var bc = new BigArith("-123"); //initialize bc to a BigArith object of value "-1
var bd = new BigArith("+123"); //initialize bd to a BigArith object of value "123"
var be = new BigArith("123"); //initialize be to a BigArith object of value "123"
```
`bigarith.js` accepts strings of digits. This can be of any length, can be negative, positive, integer, or fracton. An empty string initializes to <code>"0"</code>.
Strings that contains characters other than: digits <code>0</code> to <code>9</code>, <code>-</code> or <code>+</code> (at the start of the string), or <code>.</code> (appearing just once), will evaluate to <code>NaN</code>
`bigarith.js` accepts strings of digits. This can be of any length, can be negative, positive, integer, or fractional number. An empty string initializes to `"0"`.
Strings that contains characters other than: digits `0` to `9`, `-` or `+` (at the start of the string), or `.` (appearing just once), will evaluate to `NaN`

##### 4. Initiating with words
###### Server-side
Expand All @@ -99,7 +99,9 @@ var bd = new BigArith("point two three seven"); //initialize bd to a BigArith ob
```
`bigarith.js` accepts english words of up to (&#177;1x10^1,005)-0.0000{insert 195 more zeroes}01 (i.e. nine hundred and ninety nine trecentretrigintillion point nine nine nine nine nine {insert 195 more "nine"'s}). That is 1,005 length of characteristic (parts before the decimal point) and 200 length of mantissa (parts after the decimal point).

A negative number <em>should</em> start with the word <code>"negative"</code>, a positive number can start with the "postive" word but this can be outrightly omitted. The mantissa part <em>should be spelt out</em> after the word <code>point</code> or else the word will evaluate to <code>NaN</code>.
> *This limit only applies to when initializing with words, [initializing with strings](#init_string) can be to any length.
A negative number <em>should</em> start with the word `"negative"`, a positive number can start with the "positive" word but this can be outrightly omitted. The mantissa part <em>should be spelt out</em> after the word `point` or else the word will evaluate to `NaN`.

This is case insensitive and only [Short Scale](https://osofem.github.io/bigarith.js/documentation/short_scales.html) naming system is supported.

Expand Down Expand Up @@ -135,16 +137,16 @@ var bb = new BigArith(ba); //initialize bb to the value of ba (i.e. "3")
```

### Functions
#### toString() method
The <code>toString()</code> method returns the value of the BigArith object as a strings of digits.
#### <span id="toString">toString() method</span>
The `toString()` method returns the value of the BigArith object as a strings of digits.

```javascript
var ba = new BigArith("negative five million six hundred and thirty seven thousand eight hundred and sixty five point three two");
console.log(ba.toString());//this outputs "-5637865.32" to the console
```

#### valueOf() method
The <code>valueOf()</code> method returns the value of the BigArith object as a number.
The `valueOf()` method returns the value of the BigArith object as a number.

```javascript
var ba = new BigArith("negative five million six hundred and thirty seven thousand eight hundred and sixty five point three two");
Expand All @@ -153,9 +155,17 @@ console.log(ba.valueOf());//this outputs -5637865.32 to the console

> NOTE: Use this function with caution as JavaScript numbers looses precision once it is greater than Number.MAX_SAFE_INTEGER or lesser than Number.MIN_SAFE_INTEGER and becomes "Infinity" when it is greater than Number.MAX_VALUE and "-Infinity" when it is less than Number.MIN_VALUE.
```javascript
var ba = new BigArith("999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999");
consoole.log(ba.valueOf()); //this outputs Infinity
consoole.log(ba.toString()); //this outputs "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
```

#### toWords() method
The <code>toWords</code> method returns the value of the BigArith object in English words using the [Short Scale](https://osofem.github.io/bigarith.js/documentation/short_scales.html) naming system. If the length of the object's characteristic part (part before the decimal point) is greater than 1,005 or the length of the mantissa part (part after the decimal point) is greater than 200, a `RangeError` is thrown.
The `toWords` method returns the value of the BigArith object in English words using the [Short Scale](https://osofem.github.io/bigarith.js/documentation/short_scales.html) naming system. If the length of the object's characteristic part (part before the decimal point) is greater than 1,005 or the length of the mantissa part (part after the decimal point) is greater than 200, a `RangeError` is thrown.

> *This limit only applies to the `toWords()` method function, [toString()](#toString) outputs the value of the BigArith object to any lenth as a string of digits.*
```javascript
var ba = new BigArith(1e3);
console.log(ba.toWords());//this outputs "one thousand" to the console
Expand Down
Loading

0 comments on commit 25c5f7b

Please sign in to comment.