-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
1,322 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<html> | ||
<!--Remember to change /v0.0-beta0.0/ to the version you are targeting --> | ||
<xscript src="https://cdn.rawgit.com/osofem/bigarith.js/v0.0-beta0.0/bigarith.js"></xscript> | ||
<script src="../bigarith.js"></script> | ||
<xscript src="https://cdn.rawgit.com/osofem/assert.js/v0.0-beta0.0/assert.js"></xscript> | ||
<script src="../../assert/assert.js"></script> | ||
<script> | ||
var ba = new BigArith("zero point five"); | ||
assertDeepEqual(ba.abs(), new BigArith("0.5")); | ||
|
||
ba = new BigArith("negative zero point five"); | ||
assertDeepEqual(ba.abs(), new BigArith("0.5")); | ||
|
||
ba = new BigArith("-234"); | ||
assertDeepEqual(ba.abs(), new BigArith("234")); | ||
|
||
ba = new BigArith("-234t");//NaN | ||
assertIsNaN(ba.abs()); | ||
|
||
ba = new BigArith("+8758376"); | ||
assertDeepEqual(ba.abs(), new BigArith("8758376")); | ||
|
||
assertDeepEqual(BigArith.abs("+8758376"), new BigArith("8758376")); | ||
assertDeepEqual(BigArith.abs("-8758.376"), new BigArith("8758.376")); | ||
assertDeepEqual(BigArith.abs("-8758.376"), new BigArith("8758.376")); | ||
assertDeepEqual(BigArith.abs(null), new BigArith(0)); | ||
assertDeepEqual(BigArith.abs(), new BigArith(0)); | ||
assertIsNaN(BigArith.abs(NaN)); | ||
assertIsNaN(BigArith.abs("kj")); | ||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<html> | ||
<!--Remember to change /v0.0-beta0.0/ to the version you are targeting --> | ||
<xscript src="https://cdn.rawgit.com/osofem/bigarith.js/v0.0-beta0.0/bigarith.js"></xscript> | ||
<script src="../bigarith.js"></script> | ||
<xscript src="https://cdn.rawgit.com/osofem/assert.js/v0.0-beta0.0/assert.js"></xscript> | ||
<script src="../../assert/assert.js"></script> | ||
<script> | ||
var y = new BigArith("zero point five"); | ||
var z = new BigArith(0.5); | ||
|
||
//adding words, strings and numbers | ||
var x = new BigArith("0.5"); | ||
assertDeepEqual(x.add("point five").add(.5).add(".5").add(5e-1), new BigArith(2.5)); | ||
|
||
//adding a BigArith objects | ||
assertDeepEqual(x.add(y).add(z), new BigArith(1.5)); //"1.5" = 0.5 + 0.5 + 0.5 | ||
|
||
//adding BigArith constants | ||
var ba = new BigArith("PI"); | ||
assertDeepEqual(ba.add(new BigArith("SQRT2")), new BigArith("4.55580621596288828726433210748920096276684127475205389415162433029854888474831603747842235966975864071716193274419460367201868066540131944436948090522841694886350676862944411386135959512410173699095343")); //PI + SQRT2 | ||
|
||
ba = new BigArith("-2"); | ||
assertDeepEqual(ba.add("-3"), new BigArith("-5")); | ||
|
||
ba = new BigArith("999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"); | ||
assertDeepEqual(ba.add("0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"), new BigArith("1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")); | ||
|
||
|
||
var then = new Date(); | ||
|
||
ba = new BigArith("999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"); | ||
assertDeepEqual(ba.add("999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"), new BigArith("1999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998")); | ||
|
||
var now = new Date(); | ||
console.log(`Adding two ${ba.toString().length} digits took ${now-then} milliseconds`); | ||
|
||
|
||
ba = new BigArith("-5"); | ||
assertDeepEqual(ba.add("-3"), new BigArith("-8")); | ||
|
||
ba = new BigArith("5"); | ||
assertDeepEqual(ba.add("negative three"), new BigArith("2")); | ||
|
||
ba = new BigArith("1001"); | ||
assertDeepEqual(ba.add("-1"), new BigArith("1000")); | ||
|
||
assertDeepEqual(BigArith.add("1001","-1"), new BigArith("1000")); | ||
assertDeepEqual(BigArith.add("1001","1"), new BigArith("1002")); | ||
assertDeepEqual(BigArith.add("-1001","-1"), new BigArith("-1002")); | ||
assertDeepEqual(BigArith.add("-1001","1"), new BigArith("-1000")); | ||
assertDeepEqual(BigArith.add("0.9","0.1"), new BigArith("1")); | ||
assertDeepEqual(BigArith.add("1","-0.1"), new BigArith("0.9")); | ||
|
||
ba = new BigArith("-17031986"); | ||
ba = ba.add("+17031986").add("24011985").subtract("456785564"); | ||
console.log(ba); | ||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<html> | ||
<!--Remember to change /v0.0-beta0.0/ to the version you are targeting --> | ||
<xscript src="https://cdn.rawgit.com/osofem/bigarith.js/v0.0-beta0.0/bigarith.js"></xscript> | ||
<script src="../bigarith.js"></script> | ||
<xscript src="https://cdn.rawgit.com/osofem/assert.js/v0.0-beta0.0/assert.js"></xscript> | ||
<script src="../../assert/assert.js"></script> | ||
<script> | ||
var x = new BigArith("1.1"); | ||
var y = new BigArith("1.9"); | ||
var z = new BigArith(7.45); | ||
|
||
var a = new BigArith(".05"); | ||
var b = new BigArith("eighty three point seven three"); | ||
var c = new BigArith("56857675753763473473463574574575693849335.567787856456453"); | ||
|
||
//Ceil | ||
assertDeepEqual(x.ceil(), new BigArith(2)); | ||
assertDeepEqual(y.ceil(), new BigArith(2)); | ||
assertDeepEqual(z.ceil(), new BigArith(8)); | ||
assertDeepEqual(a.ceil(), new BigArith(1)); | ||
assertDeepEqual(b.ceil(), new BigArith(84)); | ||
assertDeepEqual(c.ceil(), new BigArith("56857675753763473473463574574575693849336")); | ||
|
||
assertDeepEqual(BigArith.ceil("0.95"), new BigArith("1")); | ||
assertDeepEqual(BigArith.ceil("7.004"), new BigArith("8")); | ||
assertDeepEqual(BigArith.ceil("-0.95"), new BigArith("-0")); | ||
|
||
//Negative | ||
assertDeepEqual(new BigArith("-45.23").ceil(), new BigArith("-45")); | ||
assertDeepEqual(new BigArith("-75.99").ceil(), new BigArith("-75")); | ||
|
||
assertIsNaN(BigArith.ceil(NaN)); | ||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<html> | ||
<!--Remember to change /v0.0-beta0.0/ to the version you are targeting --> | ||
<xscript src="https://cdn.rawgit.com/osofem/bigarith.js/v0.0-beta0.0/bigarith.js"></xscript> | ||
<script src="../bigarith.js"></script> | ||
<xscript src="https://cdn.rawgit.com/osofem/assert.js/v0.0-beta0.0/assert.js"></xscript> | ||
<script src="../../assert/assert.js"></script> | ||
<script> | ||
var x = new BigArith(2); | ||
|
||
//Compare | ||
assertEqual(x.compare("2"), 0); | ||
assertEqual(x.compare(-2), 1); | ||
assertEqual(x.compare("two"), 0); | ||
assertEqual(x.compare("two"), 0); | ||
assertEqual(x.compare("negative two"), 1); | ||
assertEqual(x.compare("-2"), 1); | ||
|
||
var ba = new BigArith(); | ||
assertEqual(ba.compare(null), 0); | ||
|
||
//Or | ||
assertEqual(BigArith.compare("+165.8987","165.898700000000000000000"), 0); | ||
assertEqual(BigArith.compare("0.123568123","0.03455893"), 1); | ||
assertEqual(BigArith.compare("2","3"), -1); | ||
|
||
assertEqual(BigArith.compare(null, "0"), 0); | ||
|
||
assertIsNaN(BigArith.compare(NaN, "0")); | ||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<html> | ||
<!--Remember to change /v0.0-beta0.0/ to the version you are targeting --> | ||
<xscript src="https://cdn.rawgit.com/osofem/bigarith.js/v0.0-beta0.0/bigarith.js"></xscript> | ||
<script src="../bigarith.js"></script> | ||
<xscript src="https://cdn.rawgit.com/osofem/assert.js/v0.0-beta0.0/assert.js"></xscript> | ||
<script src="../../assert/assert.js"></script> | ||
<script> | ||
var x = new BigArith(2); | ||
|
||
//CompareAbs | ||
assertEqual(x.compareAbs("2"), 0); | ||
assertEqual(x.compareAbs(-2), 0); | ||
assertEqual(x.compareAbs("two"), 0); | ||
assertEqual(x.compareAbs("2.0"), 0); | ||
assertEqual(x.compareAbs("negative two"), 0); | ||
assertEqual(x.compareAbs("-2"), 0); | ||
|
||
//Or | ||
assertEqual(BigArith.compareAbs("-165.8987", "165.898700000000000000000"), 0); | ||
assertEqual(BigArith.compareAbs("0.123568123", "-0.03455893"), 1); | ||
assertEqual(BigArith.compareAbs("+0.03455893", "0.123568123"), -1); | ||
|
||
assertEqual(BigArith.compareAbs("", null), 0); | ||
|
||
assertIsNaN(BigArith.compareAbs("", NaN)); | ||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<html> | ||
<!--Remember to change /v0.0-beta0.0/ to the version you are targeting --> | ||
<xscript src="https://cdn.rawgit.com/osofem/bigarith.js/v0.0-beta0.0/bigarith.js"></xscript> | ||
<script src="../bigarith.js"></script> | ||
<xscript src="https://cdn.rawgit.com/osofem/assert.js/v0.0-beta0.0/assert.js"></xscript> | ||
<script src="../../assert/assert.js"></script> | ||
<script> | ||
assertDeepEqual(BigArith.divide("426", 2), new BigArith(213)); | ||
assertDeepEqual(BigArith.divide("128", 2), new BigArith(64)); | ||
assertDeepEqual(BigArith.divide("138", 2), new BigArith(69)); | ||
assertDeepEqual(BigArith.divide("111369497863972", 2), new BigArith("55684748931986")); | ||
|
||
assertDeepEqual(BigArith.divide("9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998", 2), new BigArith("4999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999")); | ||
|
||
assertDeepEqual(BigArith.divide("999", "9"), new BigArith("111")); | ||
|
||
assertDeepEqual(BigArith.divide("999999999999999999999999999999999999999999999999999999999999999999999999999", "999"), new BigArith("1001001001001001001001001001001001001001001001001001001001001001001001001")); | ||
|
||
assertDeepEqual(BigArith.divide("888", "888"), new BigArith("1")); | ||
assertDeepEqual(BigArith.divide("20", "2"), new BigArith("10")); | ||
assertDeepEqual(BigArith.divide("408", "2"), new BigArith("204")); | ||
assertDeepEqual(BigArith.divide("4008", "2"), new BigArith("2004")); | ||
assertDeepEqual(BigArith.divide("40080", "2"), new BigArith("20040")); | ||
assertDeepEqual(BigArith.divide("300", "2"), new BigArith("150")); | ||
assertDeepEqual(BigArith.divide("3000", "2"), new BigArith("1500")); | ||
|
||
assertDeepEqual(BigArith.divide("2100", "2"), new BigArith("1050")); | ||
assertDeepEqual(BigArith.divide("20100", "2"), new BigArith("10050")); | ||
assertDeepEqual(BigArith.divide("2222", "22"), new BigArith("101")); | ||
assertDeepEqual(BigArith.divide("2010002400", "2"), new BigArith("1005001200")); | ||
assertDeepEqual(BigArith.divide("9000", "2"), new BigArith("4500")); | ||
|
||
assertDeepEqual(BigArith.divide("-4", "2"), new BigArith("-2")); | ||
assertDeepEqual(BigArith.divide("4", "-2"), new BigArith("-2")); | ||
assertDeepEqual(BigArith.divide("-4", "-2"), new BigArith("2")); | ||
assertDeepEqual(BigArith.divide("2222222222222222", "2"), new BigArith("1111111111111111")); | ||
assertDeepEqual(BigArith.divide("600000", "300"), new BigArith("2000")); | ||
|
||
//Those with reminders | ||
assertDeepEqual(BigArith.divide("21", 2), new BigArith("10.5")); | ||
assertDeepEqual(BigArith.divide("21", 5), new BigArith("4.2")); | ||
assertDeepEqual(BigArith.divide("17", 4), new BigArith("4.25")); | ||
assertDeepEqual(BigArith.divide("657654", "1000"), new BigArith("657.654")); | ||
|
||
assertDeepEqual(BigArith.divide("89", "3"), new BigArith("29.66666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666667")); | ||
|
||
assertDeepEqual(BigArith.divide("1", 3), new BigArith("0.33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333")); | ||
|
||
assertDeepEqual(BigArith.divide("4", "2"), new BigArith("2")); | ||
assertDeepEqual(BigArith.divide("22", "7"), new BigArith("3.14285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714")); | ||
|
||
assertDeepEqual(BigArith.divide("5", "708"), new BigArith("0.00706214689265536723163841807909604519774011299435028248587570621468926553672316384180790960451977401129943502824858757062146892655367231638418079096045197740112994350282485875706214689265536723163842")); | ||
|
||
assertDeepEqual(BigArith.divide("0", "2"), new BigArith(0)); | ||
assertDeepEqual(BigArith.divide("0.5", "0.2"), new BigArith("2.5")); | ||
assertDeepEqual(BigArith.divide("0.5", "0.0234"), new BigArith("21.36752136752136752136752136752136752136752136752136752136752136752136752136752136752136752136752136752136752136752136752136752136752136752136752136752136752136752136752136752136752136752136752136752137")); | ||
|
||
assertDeepEqual(BigArith.divide("0.5", "234"), new BigArith("0.00213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675")); | ||
assertDeepEqual(BigArith.divide("0.0000345", "12"), new BigArith("0.000002875")); | ||
assertDeepEqual(BigArith.divide("3.45", "12"), new BigArith("0.2875")); | ||
assertDeepEqual(BigArith.divide("345", "0.0000012"), new BigArith("287500000")); | ||
assertDeepEqual(BigArith.divide("345", "1.2"), new BigArith("287.5")); | ||
assertDeepEqual(BigArith.divide("0.5", "0.5"), new BigArith("1")); | ||
assertDeepEqual(BigArith.divide("12.25", "0.765625"), new BigArith("16")); | ||
|
||
ba = new BigArith("0.5"); | ||
ba = ba.divide("0.866025403"); | ||
assertDeepEqual(ba, new BigArith("0.5773502697125848628253229195402712684630106629793629737209914153060935095918889575575186678444350436681128163165440078898008953670380959945120686026804689469368833283519744512621415563718746943038575")); | ||
|
||
assertDeepEqual(BigArith.divide(1, new BigArith("SQRT2")), new BigArith("0.70710678118654752440084436210484903928483593768847403658833986899536623923105351942519376716382078636750692311545614851246241802792536860632206074854996791570661133296375279637789997525057639103028574")); | ||
|
||
assertDeepEqual(BigArith.divide("1","0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"), new BigArith("1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")); | ||
|
||
//Throws Error | ||
var args = ["2", "0"]; | ||
assertThrowError(BigArith.divide, args);// throws division by zero error | ||
</script> | ||
</html> |
Oops, something went wrong.