mirror of
https://github.com/Leo501/CocosCreatorTutorial.git
synced 2026-05-07 22:27:22 +08:00
添加一个处理int64的大数
This commit is contained in:
67
BigNumber64Demo/.gitignore
vendored
Normal file
67
BigNumber64Demo/.gitignore
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
# Fireball Projects
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
library/
|
||||
temp/
|
||||
local/
|
||||
build/
|
||||
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
# Logs and databases
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
*.log
|
||||
*.sql
|
||||
*.sqlite
|
||||
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
# files for debugger
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
*.sln
|
||||
*.csproj
|
||||
*.pidb
|
||||
*.unityproj
|
||||
*.suo
|
||||
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
# OS generated files
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
.DS_Store
|
||||
ehthumbs.db
|
||||
Thumbs.db
|
||||
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
# exvim files
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
*UnityVS.meta
|
||||
*.err
|
||||
*.err.meta
|
||||
*.exvim
|
||||
*.exvim.meta
|
||||
*.vimentry
|
||||
*.vimentry.meta
|
||||
*.vimproject
|
||||
*.vimproject.meta
|
||||
.vimfiles.*/
|
||||
.exvim.*/
|
||||
quick_gen_project_*_autogen.bat
|
||||
quick_gen_project_*_autogen.bat.meta
|
||||
quick_gen_project_*_autogen.sh
|
||||
quick_gen_project_*_autogen.sh.meta
|
||||
.exvim.app
|
||||
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
# webstorm files
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
.idea/
|
||||
|
||||
#//////////////////////////
|
||||
# VS Code
|
||||
#//////////////////////////
|
||||
|
||||
.vscode/
|
||||
37
BigNumber64Demo/README.md
Normal file
37
BigNumber64Demo/README.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# BigNumber64Demo
|
||||
> 介绍如何在 javascript 处理64位大数。
|
||||
### 方案1
|
||||
[long.js](https://github.com/dcodeIO/long.js) 库
|
||||
##### 介绍
|
||||
A Long class for representing a 64 bit two's-complement integer value derived from the Closure Library for stand-alone use and extended with unsigned support.
|
||||
|
||||
##### 简单使用
|
||||
~~~
|
||||
var Long = require("long");
|
||||
|
||||
var longVal = new Long(0xFFFFFFFF, 0x7FFFFFFF);
|
||||
|
||||
console.log(longVal.toString());
|
||||
~~~
|
||||
|
||||
##### 优势
|
||||
* 可以把服务器发过来的高位、底位数据合成一个大数。显示,+、-、*、/、。
|
||||
|
||||
### 方案2
|
||||
[bignumber.js](https://github.com/alexbardas/bignumber.js) 库
|
||||
##### 介绍
|
||||
BigNumber.js is a light javascript library for node.js and the browser. It supports arithmetic operations on Big Integers.
|
||||
|
||||
It is build with performance in mind, uses the fastest algorithms and supports all basic arithmetic operations (+, -, *, /, %, ^, abs). Works with both positive and negative big integers.
|
||||
|
||||
##### 简单介绍
|
||||
~~~
|
||||
var BigNumber = require('big-number');
|
||||
|
||||
BigNumber(5).plus(97).minus(53).plus(434).multiply(5435423).add(321453).multiply(21).div(2).pow(2);
|
||||
// 760056543044267246001
|
||||
~~~
|
||||
|
||||
##### 优势
|
||||
* 支持add/plus, minus/subtract, multiply/mult, divide/div, power/pow, mod, equals, lt, lte, gt, gte, isZero, abs
|
||||
|
||||
6
BigNumber64Demo/assets/Scene.meta
Normal file
6
BigNumber64Demo/assets/Scene.meta
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"ver": "1.0.1",
|
||||
"uuid": "29f52784-2fca-467b-92e7-8fd9ef8c57b7",
|
||||
"isGroup": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
368
BigNumber64Demo/assets/Scene/helloworld.fire
Normal file
368
BigNumber64Demo/assets/Scene/helloworld.fire
Normal file
@@ -0,0 +1,368 @@
|
||||
[
|
||||
{
|
||||
"__type__": "cc.SceneAsset",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"_rawFiles": null,
|
||||
"scene": {
|
||||
"__id__": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Scene",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"_opacity": 255,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255
|
||||
},
|
||||
"_cascadeOpacityEnabled": true,
|
||||
"_parent": null,
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"_children": [
|
||||
{
|
||||
"__id__": 2
|
||||
}
|
||||
],
|
||||
"_localZOrder": 0,
|
||||
"_globalZOrder": 0,
|
||||
"_ignoreAnchorPointForPosition": false,
|
||||
"_tag": -1,
|
||||
"_opacityModifyRGB": false,
|
||||
"_id": "2d2f792f-a40c-49bb-a189-ed176a246e49"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "Canvas",
|
||||
"_objFlags": 0,
|
||||
"_opacity": 255,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 252,
|
||||
"g": 252,
|
||||
"b": 252,
|
||||
"a": 255
|
||||
},
|
||||
"_cascadeOpacityEnabled": true,
|
||||
"_parent": {
|
||||
"__id__": 1
|
||||
},
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0.5,
|
||||
"y": 0.5
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 960,
|
||||
"height": 640
|
||||
},
|
||||
"_children": [
|
||||
{
|
||||
"__id__": 3
|
||||
},
|
||||
{
|
||||
"__id__": 6
|
||||
},
|
||||
{
|
||||
"__id__": 8
|
||||
}
|
||||
],
|
||||
"_rotationX": 0,
|
||||
"_rotationY": 0,
|
||||
"_scaleX": 1,
|
||||
"_scaleY": 1,
|
||||
"_position": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 480,
|
||||
"y": 320
|
||||
},
|
||||
"_skewX": 0,
|
||||
"_skewY": 0,
|
||||
"_localZOrder": 0,
|
||||
"_globalZOrder": 0,
|
||||
"_ignoreAnchorPointForPosition": false,
|
||||
"_tag": -1,
|
||||
"_opacityModifyRGB": false,
|
||||
"_id": "a286bbGknJLZpRpxROV6M94",
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 10
|
||||
},
|
||||
{
|
||||
"__id__": 11
|
||||
}
|
||||
],
|
||||
"_prefab": null
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "background",
|
||||
"_objFlags": 0,
|
||||
"_opacity": 255,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 27,
|
||||
"g": 38,
|
||||
"b": 46,
|
||||
"a": 255
|
||||
},
|
||||
"_cascadeOpacityEnabled": true,
|
||||
"_parent": {
|
||||
"__id__": 2
|
||||
},
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0.5,
|
||||
"y": 0.5
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 960,
|
||||
"height": 640
|
||||
},
|
||||
"_children": [],
|
||||
"_rotationX": 0,
|
||||
"_rotationY": 0,
|
||||
"_scaleX": 1,
|
||||
"_scaleY": 1,
|
||||
"_position": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0
|
||||
},
|
||||
"_skewX": 0,
|
||||
"_skewY": 0,
|
||||
"_localZOrder": 0,
|
||||
"_globalZOrder": 0,
|
||||
"_ignoreAnchorPointForPosition": false,
|
||||
"_tag": -1,
|
||||
"_opacityModifyRGB": false,
|
||||
"_id": "e2e0crkOLxGrpMxpbC4iQg1",
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 4
|
||||
},
|
||||
{
|
||||
"__id__": 5
|
||||
}
|
||||
],
|
||||
"_prefab": null
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Widget",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 3
|
||||
},
|
||||
"_enabled": true,
|
||||
"_alignFlags": 45,
|
||||
"_left": 0,
|
||||
"_right": 0,
|
||||
"_top": 0,
|
||||
"_bottom": 0,
|
||||
"_isAbsLeft": true,
|
||||
"_isAbsRight": true,
|
||||
"_isAbsTop": true,
|
||||
"_isAbsBottom": true,
|
||||
"_originalWidth": 200,
|
||||
"_originalHeight": 150
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Sprite",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 3
|
||||
},
|
||||
"_enabled": true,
|
||||
"_spriteFrame": {
|
||||
"__uuid__": "410fb916-8721-4663-bab8-34397391ace7"
|
||||
},
|
||||
"_type": 1,
|
||||
"_useOriginalSize": false,
|
||||
"_atlas": null
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "cocos",
|
||||
"_objFlags": 0,
|
||||
"_opacity": 255,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255
|
||||
},
|
||||
"_cascadeOpacityEnabled": true,
|
||||
"_parent": {
|
||||
"__id__": 2
|
||||
},
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0.5,
|
||||
"y": 0.5
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 195,
|
||||
"height": 270
|
||||
},
|
||||
"_children": [],
|
||||
"_rotationX": 0,
|
||||
"_rotationY": 0,
|
||||
"_scaleX": 1,
|
||||
"_scaleY": 1,
|
||||
"_position": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 50
|
||||
},
|
||||
"_skewX": 0,
|
||||
"_skewY": 0,
|
||||
"_localZOrder": 0,
|
||||
"_globalZOrder": 0,
|
||||
"_ignoreAnchorPointForPosition": false,
|
||||
"_tag": -1,
|
||||
"_opacityModifyRGB": false,
|
||||
"_id": "c4f30YOS65G64U2TwufdJ+2",
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 7
|
||||
}
|
||||
],
|
||||
"_prefab": null
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Sprite",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 6
|
||||
},
|
||||
"_enabled": true,
|
||||
"_spriteFrame": {
|
||||
"__uuid__": "31bc895a-c003-4566-a9f3-2e54ae1c17dc"
|
||||
},
|
||||
"_type": 0,
|
||||
"_useOriginalSize": true,
|
||||
"_atlas": null
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "label",
|
||||
"_objFlags": 0,
|
||||
"_opacity": 255,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255
|
||||
},
|
||||
"_cascadeOpacityEnabled": true,
|
||||
"_parent": {
|
||||
"__id__": 2
|
||||
},
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0.5,
|
||||
"y": 0.5
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 492,
|
||||
"height": 112
|
||||
},
|
||||
"_children": [],
|
||||
"_rotationX": 0,
|
||||
"_rotationY": 0,
|
||||
"_scaleX": 1,
|
||||
"_scaleY": 1,
|
||||
"_position": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": -180
|
||||
},
|
||||
"_skewX": 0,
|
||||
"_skewY": 0,
|
||||
"_localZOrder": 0,
|
||||
"_globalZOrder": 0,
|
||||
"_ignoreAnchorPointForPosition": false,
|
||||
"_tag": -1,
|
||||
"_opacityModifyRGB": false,
|
||||
"_id": "31f1bH7V69Ajr1iXhluMpTB",
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 9
|
||||
}
|
||||
],
|
||||
"_prefab": null
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Label",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 8
|
||||
},
|
||||
"_enabled": true,
|
||||
"_useOriginalSize": false,
|
||||
"_fontSize": 60,
|
||||
"_lineHeight": 60,
|
||||
"_enableWrapText": true,
|
||||
"_isSystemFontUsed": true,
|
||||
"_N$string": "Label",
|
||||
"_N$horizontalAlign": 1,
|
||||
"_N$verticalAlign": 1,
|
||||
"_N$overflow": 0
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Canvas",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 2
|
||||
},
|
||||
"_enabled": true,
|
||||
"_designResolution": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 960,
|
||||
"height": 640
|
||||
},
|
||||
"_fitWidth": false,
|
||||
"_fitHeight": true
|
||||
},
|
||||
{
|
||||
"__type__": "280c3rsZJJKnZ9RqbALVwtK",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 2
|
||||
},
|
||||
"_enabled": true,
|
||||
"label": {
|
||||
"__id__": 9
|
||||
},
|
||||
"text": "Hello, World!"
|
||||
}
|
||||
]
|
||||
7
BigNumber64Demo/assets/Scene/helloworld.fire.meta
Normal file
7
BigNumber64Demo/assets/Scene/helloworld.fire.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"ver": "1.0.0",
|
||||
"uuid": "2d2f792f-a40c-49bb-a189-ed176a246e49",
|
||||
"asyncLoadAssets": false,
|
||||
"autoReleaseAssets": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
6
BigNumber64Demo/assets/Script.meta
Normal file
6
BigNumber64Demo/assets/Script.meta
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"ver": "1.0.1",
|
||||
"uuid": "4734c20c-0db8-4eb2-92ea-e692f4d70934",
|
||||
"isGroup": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
22
BigNumber64Demo/assets/Script/HelloWorld.js
Normal file
22
BigNumber64Demo/assets/Script/HelloWorld.js
Normal file
@@ -0,0 +1,22 @@
|
||||
cc.Class({
|
||||
extends: cc.Component,
|
||||
|
||||
properties: {
|
||||
label: {
|
||||
default: null,
|
||||
type: cc.Label
|
||||
},
|
||||
// defaults, set visually when attaching this script to the Canvas
|
||||
text: 'Hello, World!'
|
||||
},
|
||||
|
||||
// use this for initialization
|
||||
onLoad: function () {
|
||||
this.label.string = this.text;
|
||||
},
|
||||
|
||||
// called every frame
|
||||
update: function (dt) {
|
||||
|
||||
},
|
||||
});
|
||||
9
BigNumber64Demo/assets/Script/HelloWorld.js.meta
Normal file
9
BigNumber64Demo/assets/Script/HelloWorld.js.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "280c3aec-6492-4a9d-9f51-a9b00b570b4a",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
5
BigNumber64Demo/assets/Script/libs.meta
Normal file
5
BigNumber64Demo/assets/Script/libs.meta
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.1",
|
||||
"uuid": "94d574ff-9875-4cb1-a36d-07c01b4e4092",
|
||||
"subMetas": {}
|
||||
}
|
||||
432
BigNumber64Demo/assets/Script/libs/bignumber.js
Normal file
432
BigNumber64Demo/assets/Script/libs/bignumber.js
Normal file
@@ -0,0 +1,432 @@
|
||||
/**
|
||||
* big-number.js -> Arithmetic operations on big integers
|
||||
* Pure javascript implementation, no external libraries needed
|
||||
* Copyright(c) 2012-2018 Alex Bardas <alex.bardas@gmail.com>
|
||||
* MIT Licensed
|
||||
* It supports the following operations:
|
||||
* addition, subtraction, multiplication, division, power, absolute value
|
||||
* It works with both positive and negative integers
|
||||
*/
|
||||
|
||||
!(function() {
|
||||
'use strict';
|
||||
|
||||
// Helper function which tests if a given character is a digit
|
||||
var testDigit = function(digit) {
|
||||
return (/^\d$/.test(digit));
|
||||
};
|
||||
|
||||
// Helper function which returns the absolute value of a given number
|
||||
var abs = function(number) {
|
||||
var bigNumber;
|
||||
if (typeof number === 'undefined') {
|
||||
return;
|
||||
}
|
||||
bigNumber = BigNumber(number);
|
||||
bigNumber.sign = 1;
|
||||
return bigNumber;
|
||||
};
|
||||
|
||||
// Check if argument is valid array
|
||||
var isArray = function(arg) {
|
||||
return Object.prototype.toString.call(arg) === '[object Array]';
|
||||
};
|
||||
|
||||
var isValidType = function(number) {
|
||||
return [
|
||||
typeof number === 'number',
|
||||
typeof number === 'string' && number.length > 0,
|
||||
isArray(number) && number.length > 0,
|
||||
number instanceof BigNumber
|
||||
].some(function(bool) {
|
||||
return bool === true;
|
||||
});
|
||||
};
|
||||
|
||||
var errors = {
|
||||
'invalid': 'Invalid Number',
|
||||
'division by zero': 'Invalid Number - Division By Zero'
|
||||
};
|
||||
|
||||
// Constructor function which creates a new BigNumber object
|
||||
// from an integer, a string, an array or other BigNumber object
|
||||
function BigNumber(initialNumber) {
|
||||
var index;
|
||||
|
||||
if (!(this instanceof BigNumber)) {
|
||||
return new BigNumber(initialNumber);
|
||||
}
|
||||
|
||||
this.number = [];
|
||||
this.sign = 1;
|
||||
this.rest = 0;
|
||||
|
||||
// The initial number can be an array, string, number of another big number
|
||||
// e.g. array : [3,2,1], ['+',3,2,1], ['-',3,2,1]
|
||||
// number : 312
|
||||
// string : '321', '+321', -321'
|
||||
// BigNumber : BigNumber(321)
|
||||
// Every character except the first must be a digit
|
||||
|
||||
if (!isValidType(initialNumber)) {
|
||||
this.number = errors['invalid'];
|
||||
return;
|
||||
}
|
||||
|
||||
if (isArray(initialNumber)) {
|
||||
if (initialNumber.length && initialNumber[0] === '-' || initialNumber[0] === '+') {
|
||||
this.sign = initialNumber[0] === '+' ? 1 : -1;
|
||||
initialNumber.shift(0);
|
||||
}
|
||||
for (index = initialNumber.length - 1; index >= 0; index--) {
|
||||
if (!this.addDigit(initialNumber[index]))
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
initialNumber = initialNumber.toString();
|
||||
if (initialNumber.charAt(0) === '-' || initialNumber.charAt(0) === '+') {
|
||||
this.sign = initialNumber.charAt(0) === '+' ? 1 : -1;
|
||||
initialNumber = initialNumber.substring(1);
|
||||
}
|
||||
|
||||
for (index = initialNumber.length - 1; index >= 0; index--) {
|
||||
if (!this.addDigit(parseInt(initialNumber.charAt(index), 10))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BigNumber.prototype.addDigit = function(digit) {
|
||||
if (testDigit(digit)) {
|
||||
this.number.push(digit);
|
||||
} else {
|
||||
this.number = errors['invalid'];
|
||||
return false;
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
BigNumber.prototype.isEven = function() {
|
||||
return this.number[0] % 2 === 0;
|
||||
};
|
||||
|
||||
// returns:
|
||||
// null if this.number is not a number
|
||||
// 0 if this.number === number
|
||||
// -1 if this.number < number
|
||||
// 1 if this.number > number
|
||||
BigNumber.prototype._compare = function(number) {
|
||||
var bigNumber;
|
||||
var index;
|
||||
|
||||
if (!isValidType(number)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
bigNumber = BigNumber(number);
|
||||
|
||||
// If the numbers have different signs, then the positive
|
||||
// number is greater
|
||||
if (this.sign !== bigNumber.sign) {
|
||||
return this.sign;
|
||||
}
|
||||
|
||||
// Else, check the length
|
||||
if (this.number.length > bigNumber.number.length) {
|
||||
return this.sign;
|
||||
} else if (this.number.length < bigNumber.number.length) {
|
||||
return this.sign * (-1);
|
||||
}
|
||||
|
||||
// If they have similar length, compare the numbers
|
||||
// digit by digit
|
||||
for (index = this.number.length - 1; index >= 0; index--) {
|
||||
if (this.number[index] > bigNumber.number[index]) {
|
||||
return this.sign;
|
||||
} else if (this.number[index] < bigNumber.number[index]) {
|
||||
return this.sign * (-1);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
// Greater than
|
||||
BigNumber.prototype.gt = function(number) {
|
||||
return this._compare(number) > 0;
|
||||
};
|
||||
|
||||
// Greater than or equal
|
||||
BigNumber.prototype.gte = function(number) {
|
||||
return this._compare(number) >= 0;
|
||||
};
|
||||
|
||||
// this.number equals n
|
||||
BigNumber.prototype.equals = function(number) {
|
||||
return this._compare(number) === 0;
|
||||
};
|
||||
|
||||
// Less than or equal
|
||||
BigNumber.prototype.lte = function(number) {
|
||||
return this._compare(number) <= 0;
|
||||
};
|
||||
|
||||
// Less than
|
||||
BigNumber.prototype.lt = function(number) {
|
||||
return this._compare(number) < 0;
|
||||
};
|
||||
|
||||
// Addition
|
||||
BigNumber.prototype.add = function(number) {
|
||||
var bigNumber;
|
||||
if (typeof number === 'undefined') {
|
||||
return this;
|
||||
}
|
||||
bigNumber = BigNumber(number);
|
||||
|
||||
if (this.sign !== bigNumber.sign) {
|
||||
if (this.sign > 0) {
|
||||
bigNumber.sign = 1;
|
||||
return this.minus(bigNumber);
|
||||
}
|
||||
else {
|
||||
this.sign = 1;
|
||||
return bigNumber.minus(this);
|
||||
}
|
||||
}
|
||||
|
||||
this.number = BigNumber._add(this, bigNumber);
|
||||
return this;
|
||||
};
|
||||
|
||||
// Subtraction
|
||||
BigNumber.prototype.subtract = function(number) {
|
||||
var bigNumber;
|
||||
if (typeof number === 'undefined') {
|
||||
return this;
|
||||
}
|
||||
bigNumber = BigNumber(number);
|
||||
|
||||
if (this.sign !== bigNumber.sign) {
|
||||
this.number = BigNumber._add(this, bigNumber);
|
||||
return this;
|
||||
}
|
||||
|
||||
// If current number is lesser than the given bigNumber, the result will be negative
|
||||
this.sign = (this.lt(bigNumber)) ? -1 : 1;
|
||||
this.number = (abs(this).lt(abs(bigNumber)))
|
||||
? BigNumber._subtract(bigNumber, this)
|
||||
: BigNumber._subtract(this, bigNumber);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
// adds two positive BigNumbers
|
||||
BigNumber._add = function(a, b) {
|
||||
var index;
|
||||
var remainder = 0;
|
||||
var length = Math.max(a.number.length, b.number.length);
|
||||
|
||||
for (index = 0; index < length || remainder > 0; index++) {
|
||||
a.number[index] = (remainder += (a.number[index] || 0) + (b.number[index] || 0)) % 10;
|
||||
remainder = Math.floor(remainder / 10);
|
||||
}
|
||||
|
||||
return a.number;
|
||||
};
|
||||
|
||||
// a - b
|
||||
// a and b are 2 positive BigNumbers and a > b
|
||||
BigNumber._subtract = function(a, b) {
|
||||
var index;
|
||||
var remainder = 0;
|
||||
var length = a.number.length;
|
||||
|
||||
for (index = 0; index < length; index++) {
|
||||
a.number[index] -= (b.number[index] || 0) + remainder;
|
||||
a.number[index] += (remainder = (a.number[index] < 0) ? 1 : 0) * 10;
|
||||
}
|
||||
// Count the zeroes which will be removed
|
||||
index = 0;
|
||||
length = a.number.length - 1;
|
||||
while (a.number[length - index] === 0 && length - index > 0) {
|
||||
index++;
|
||||
}
|
||||
if (index > 0) {
|
||||
a.number.splice(-index);
|
||||
}
|
||||
return a.number;
|
||||
};
|
||||
|
||||
// this.number * number
|
||||
BigNumber.prototype.multiply = function(number) {
|
||||
if (typeof number === 'undefined') {
|
||||
return this;
|
||||
}
|
||||
var bigNumber = BigNumber(number);
|
||||
var index;
|
||||
var givenNumberIndex;
|
||||
var remainder = 0;
|
||||
var result = [];
|
||||
|
||||
if (this.isZero() || bigNumber.isZero()) {
|
||||
return BigNumber(0);
|
||||
}
|
||||
|
||||
this.sign *= bigNumber.sign;
|
||||
|
||||
// multiply the numbers
|
||||
for (index = 0; index < this.number.length; index++) {
|
||||
for (remainder = 0, givenNumberIndex = 0; givenNumberIndex < bigNumber.number.length || remainder > 0; givenNumberIndex++) {
|
||||
result[index + givenNumberIndex] = (remainder += (result[index + givenNumberIndex] || 0) + this.number[index] * (bigNumber.number[givenNumberIndex] || 0)) % 10;
|
||||
remainder = Math.floor(remainder / 10);
|
||||
}
|
||||
}
|
||||
|
||||
this.number = result;
|
||||
return this;
|
||||
};
|
||||
|
||||
// this.number / number
|
||||
BigNumber.prototype.divide = function(number) {
|
||||
if (typeof number === 'undefined') {
|
||||
return this;
|
||||
}
|
||||
|
||||
var bigNumber = BigNumber(number);
|
||||
var index;
|
||||
var length;
|
||||
var result = [];
|
||||
var rest = BigNumber(0);
|
||||
|
||||
// test if one of the numbers is zero
|
||||
if (bigNumber.isZero()) {
|
||||
this.number = errors['division by zero'];
|
||||
return this;
|
||||
} else if (this.isZero()) {
|
||||
this.rest = BigNumber(0);
|
||||
return this;
|
||||
}
|
||||
|
||||
this.sign *= bigNumber.sign;
|
||||
bigNumber.sign = 1;
|
||||
|
||||
// Skip division by 1
|
||||
if (bigNumber.number.length === 1 && bigNumber.number[0] === 1) {
|
||||
this.rest = BigNumber(0);
|
||||
return this;
|
||||
}
|
||||
|
||||
for (index = this.number.length - 1; index >= 0; index--) {
|
||||
rest.multiply(10);
|
||||
rest.number[0] = this.number[index];
|
||||
result[index] = 0;
|
||||
while (bigNumber.lte(rest)) {
|
||||
result[index]++;
|
||||
rest.subtract(bigNumber);
|
||||
}
|
||||
}
|
||||
|
||||
index = 0;
|
||||
length = result.length - 1;
|
||||
while (result[length - index] === 0 && length - index > 0) {
|
||||
index++;
|
||||
}
|
||||
if (index > 0) {
|
||||
result.splice(-index);
|
||||
}
|
||||
|
||||
this.rest = rest;
|
||||
this.number = result;
|
||||
return this;
|
||||
};
|
||||
|
||||
// this.number % number
|
||||
BigNumber.prototype.mod = function(number) {
|
||||
return this.divide(number).rest;
|
||||
};
|
||||
|
||||
BigNumber.prototype.power = function(number) {
|
||||
if (typeof number === 'undefined')
|
||||
return;
|
||||
var bigNumber;
|
||||
var bigNumberPower;
|
||||
// Convert the argument to a big number
|
||||
if (!isValidType(number)) {
|
||||
this.number = errors['invalid'];
|
||||
return;
|
||||
}
|
||||
bigNumberPower = BigNumber(number);
|
||||
if (bigNumberPower.isZero()) {
|
||||
return BigNumber(1);
|
||||
}
|
||||
if (bigNumberPower.val() === '1') {
|
||||
return this;
|
||||
}
|
||||
|
||||
bigNumber = BigNumber(this);
|
||||
|
||||
this.number = [1];
|
||||
while (bigNumberPower.gt(0)) {
|
||||
if (!bigNumberPower.isEven()) {
|
||||
this.multiply(bigNumber);
|
||||
bigNumberPower.subtract(1);
|
||||
continue;
|
||||
}
|
||||
bigNumber.multiply(bigNumber);
|
||||
bigNumberPower.div(2);
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
// |this.number|
|
||||
BigNumber.prototype.abs = function() {
|
||||
this.sign = 1;
|
||||
return this;
|
||||
};
|
||||
|
||||
// Check if this.number is equal to 0
|
||||
BigNumber.prototype.isZero = function() {
|
||||
var index;
|
||||
for (index = 0; index < this.number.length; index++) {
|
||||
if (this.number[index] !== 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
// this.number.toString()
|
||||
BigNumber.prototype.toString = function() {
|
||||
var index;
|
||||
var str = '';
|
||||
if (typeof this.number === 'string') {
|
||||
return this.number;
|
||||
}
|
||||
|
||||
for (index = this.number.length - 1; index >= 0; index--) {
|
||||
str += this.number[index];
|
||||
}
|
||||
|
||||
return (this.sign > 0) ? str : ('-' + str);
|
||||
};
|
||||
|
||||
// Use shorcuts for functions names
|
||||
BigNumber.prototype.plus = BigNumber.prototype.add;
|
||||
BigNumber.prototype.minus = BigNumber.prototype.subtract;
|
||||
BigNumber.prototype.div = BigNumber.prototype.divide;
|
||||
BigNumber.prototype.mult = BigNumber.prototype.multiply;
|
||||
BigNumber.prototype.pow = BigNumber.prototype.power;
|
||||
BigNumber.prototype.val = BigNumber.prototype.toString;
|
||||
|
||||
// CommonJS
|
||||
if (typeof exports === 'object' && typeof module !== 'undefined') {
|
||||
module.exports = BigNumber;
|
||||
} else if (typeof window !== 'undefined') {
|
||||
window.BigNumber = BigNumber;
|
||||
}
|
||||
})();
|
||||
9
BigNumber64Demo/assets/Script/libs/bignumber.js.meta
Normal file
9
BigNumber64Demo/assets/Script/libs/bignumber.js.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "c8022bc5-283a-4bdc-ad83-0cd80ee9e648",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
1405
BigNumber64Demo/assets/Script/libs/long.js
Normal file
1405
BigNumber64Demo/assets/Script/libs/long.js
Normal file
File diff suppressed because it is too large
Load Diff
9
BigNumber64Demo/assets/Script/libs/long.js.meta
Normal file
9
BigNumber64Demo/assets/Script/libs/long.js.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "d495a67e-8f57-4dfb-9d2f-4e2565cee8d0",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
6
BigNumber64Demo/assets/Texture.meta
Normal file
6
BigNumber64Demo/assets/Texture.meta
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"ver": "1.0.1",
|
||||
"uuid": "7b81d4e8-ec84-4716-968d-500ac1d78a54",
|
||||
"isGroup": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
BIN
BigNumber64Demo/assets/Texture/HelloWorld.png
Normal file
BIN
BigNumber64Demo/assets/Texture/HelloWorld.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 37 KiB |
30
BigNumber64Demo/assets/Texture/HelloWorld.png.meta
Normal file
30
BigNumber64Demo/assets/Texture/HelloWorld.png.meta
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"ver": "1.0.0",
|
||||
"uuid": "6aa0aa6a-ebee-4155-a088-a687a6aadec4",
|
||||
"type": "sprite",
|
||||
"wrapMode": "clamp",
|
||||
"filterMode": "bilinear",
|
||||
"subMetas": {
|
||||
"HelloWorld": {
|
||||
"ver": "1.0.3",
|
||||
"uuid": "31bc895a-c003-4566-a9f3-2e54ae1c17dc",
|
||||
"rawTextureUuid": "6aa0aa6a-ebee-4155-a088-a687a6aadec4",
|
||||
"trimType": "auto",
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": 0,
|
||||
"offsetY": 0,
|
||||
"trimX": 0,
|
||||
"trimY": 0,
|
||||
"width": 195,
|
||||
"height": 270,
|
||||
"rawWidth": 195,
|
||||
"rawHeight": 270,
|
||||
"borderTop": 0,
|
||||
"borderBottom": 0,
|
||||
"borderLeft": 0,
|
||||
"borderRight": 0,
|
||||
"subMetas": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
BigNumber64Demo/assets/Texture/singleColor.png
Normal file
BIN
BigNumber64Demo/assets/Texture/singleColor.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
30
BigNumber64Demo/assets/Texture/singleColor.png.meta
Normal file
30
BigNumber64Demo/assets/Texture/singleColor.png.meta
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"ver": "1.0.0",
|
||||
"uuid": "a8027877-d8d6-4645-97a0-52d4a0123dba",
|
||||
"type": "sprite",
|
||||
"wrapMode": "clamp",
|
||||
"filterMode": "bilinear",
|
||||
"subMetas": {
|
||||
"singleColor": {
|
||||
"ver": "1.0.3",
|
||||
"uuid": "410fb916-8721-4663-bab8-34397391ace7",
|
||||
"rawTextureUuid": "a8027877-d8d6-4645-97a0-52d4a0123dba",
|
||||
"trimType": "auto",
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": 0,
|
||||
"offsetY": 0,
|
||||
"trimX": 0,
|
||||
"trimY": 0,
|
||||
"width": 2,
|
||||
"height": 2,
|
||||
"rawWidth": 2,
|
||||
"rawHeight": 2,
|
||||
"borderTop": 0,
|
||||
"borderBottom": 0,
|
||||
"borderLeft": 0,
|
||||
"borderRight": 0,
|
||||
"subMetas": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
20635
BigNumber64Demo/creator.d.ts
vendored
Normal file
20635
BigNumber64Demo/creator.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
15
BigNumber64Demo/jsconfig.json
Normal file
15
BigNumber64Demo/jsconfig.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"experimentalDecorators": true
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
".vscode",
|
||||
"library",
|
||||
"local",
|
||||
"settings",
|
||||
"temp"
|
||||
]
|
||||
}
|
||||
4
BigNumber64Demo/project.json
Normal file
4
BigNumber64Demo/project.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"engine": "cocos2d-html5",
|
||||
"packages": "packages"
|
||||
}
|
||||
13
BigNumber64Demo/settings/builder.json
Normal file
13
BigNumber64Demo/settings/builder.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"excludeScenes": [],
|
||||
"orientation": {
|
||||
"landscapeLeft": true,
|
||||
"landscapeRight": true,
|
||||
"portrait": false,
|
||||
"upsideDown": false
|
||||
},
|
||||
"packageName": "org.cocos2d.helloworld",
|
||||
"startScene": "2d2f792f-a40c-49bb-a189-ed176a246e49",
|
||||
"title": "hello_world",
|
||||
"webOrientation": "auto"
|
||||
}
|
||||
7
BigNumber64Demo/settings/builder.panel.json
Normal file
7
BigNumber64Demo/settings/builder.panel.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"excludeScenes": [],
|
||||
"packageName": "org.cocos2d.helloworld",
|
||||
"platform": "web-mobile",
|
||||
"startScene": "2d2f792f-a40c-49bb-a189-ed176a246e49",
|
||||
"title": "HelloWorld"
|
||||
}
|
||||
28
BigNumber64Demo/settings/project.json
Normal file
28
BigNumber64Demo/settings/project.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"collision-matrix": [
|
||||
[
|
||||
true
|
||||
]
|
||||
],
|
||||
"excluded-modules": [],
|
||||
"group-list": [
|
||||
"default"
|
||||
],
|
||||
"start-scene": "current",
|
||||
"design-resolution-width": 960,
|
||||
"design-resolution-height": 640,
|
||||
"fit-width": false,
|
||||
"fit-height": true,
|
||||
"use-project-simulator-setting": false,
|
||||
"simulator-orientation": false,
|
||||
"use-customize-simulator": false,
|
||||
"simulator-resolution": {
|
||||
"width": 960,
|
||||
"height": 640
|
||||
},
|
||||
"cocos-analytics": {
|
||||
"enable": false,
|
||||
"appID": "13798",
|
||||
"appSecret": "959b3ac0037d0f3c2fdce94f8421a9b2"
|
||||
}
|
||||
}
|
||||
BIN
BigNumber64Demo/template-banner.png
Normal file
BIN
BigNumber64Demo/template-banner.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
5
BigNumber64Demo/template.json
Normal file
5
BigNumber64Demo/template.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "TEMPLATES.helloworld.name",
|
||||
"desc": "TEMPLATES.helloworld.desc",
|
||||
"banner": "template-banner.png"
|
||||
}
|
||||
Reference in New Issue
Block a user