#1659: Added BigInteger.js (flattened commit)

This commit is contained in:
Ingo Bürk
2014-04-21 00:32:05 +02:00
parent 5f90111fc7
commit c5d83cb079
3 changed files with 257 additions and 0 deletions

View File

@@ -22,6 +22,7 @@ All definitions files include a header with the author and editors, so at some p
* [Atom](https://atom.io/) (by [vvakame](https://github.com/vvakame))
* [Backbone.js](http://backbonejs.org/) (by [Boris Yankov](https://github.com/borisyankov))
* [Backbone Relational](http://backbonerelational.org/) (by [Eirik Hoem](https://github.com/eirikhm))
* [BigInteger](https://github.com/peterolson/BigInteger.js) (by [Ingo Bürk](https://github.com/Airblader))
* [BigScreen](http://brad.is/coding/BigScreen/) (by [Douglas Eichelberger](https://github.com/dduugg))
* [Bluebird](https://github.com/petkaantonov/bluebird) (by [Bart van der Schoor](https://github.com/Bartvds))
* [Bootbox](https://github.com/makeusabrew/bootbox) (by [Vincent Bortone](https://github.com/vbortone/))

View File

@@ -0,0 +1,95 @@
/// <reference path="bigInteger.d.ts" />
// constructor tests
var noArgument = bigInt(),
numberArgument = bigInt( 93 ),
stringArgument = bigInt( "75643564363473453456342378564387956906736546456235345" ),
bigIntArgument = bigInt( noArgument );
// method tests
var x = bigInt(),
isBigInteger: BigInteger,
isNumber: number,
isBoolean: boolean,
isString: string,
isDivmod: {
quotient: BigInteger;
remainder: BigInteger;
};
isBigInteger = x.abs();
isBigInteger = x.add( 0 );
isBigInteger = x.add( x );
isBigInteger = x.compare( 0 );
isBigInteger = x.compare( x );
isBigInteger = x.compareAbs( 0 );
isBigInteger = x.compareAbs( x );
isBigInteger = x.divide( 0 );
isBigInteger = x.divide( x );
isDivmod = x.divmod( 0 );
isDivmod = x.divmod( x );
isBoolean = x.equals( 0 );
isBoolean = x.equals( x );
isBoolean = x.greater( 0 );
isBoolean = x.greater( x );
isBoolean = x.greaterOrEquals( 0 );
isBoolean = x.greaterOrEquals( x );
isBoolean = x.isEven();
isBoolean = x.isNegative();
isBoolean = x.isOdd();
isBoolean = x.isPositive();
isBoolean = x.lesser( 0 );
isBoolean = x.lesser( x );
isBoolean = x.lesserOrEquals( 0 );
isBoolean = x.lesserOrEquals( x );
isBigInteger = x.minus( 0 );
isBigInteger = x.minus( x );
isBigInteger = x.mod( 0 );
isBigInteger = x.mod( x );
isBigInteger = x.multiply( 0 );
isBigInteger = x.multiply( x );
isBigInteger = x.next();
isBoolean = x.notEquals( 0 );
isBoolean = x.notEquals( x );
isBigInteger = x.over( 0 );
isBigInteger = x.over( x );
isBigInteger = x.plus( 0 );
isBigInteger = x.plus( x );
isBigInteger = x.pow( 0 );
isBigInteger = x.pow( x );
isBigInteger = x.prev();
isBigInteger = x.subtract( 0 );
isBigInteger = x.subtract( x );
isBigInteger = x.times( 0 );
isBigInteger = x.times( x );
isNumber = x.toJSNumber();
isString = x.toString();
isNumber = x.valueOf();

161
bigInteger/bigInteger.d.ts vendored Normal file
View File

@@ -0,0 +1,161 @@
// Type definitions for BigInteger.js
// Project: https://github.com/peterolson/BigInteger.js
// Definitions by: Ingo Bürk <https://github.com/Airblader>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
interface BigInteger {
/** Returns the absolute value of a bigInt. */
abs(): BigInteger;
/** Performs addition */
add( number: number ): BigInteger;
/** Performs addition */
add( number: BigInteger ): BigInteger;
/** Alias for the add method. */
plus( number: number ): BigInteger;
/** Alias for the add method. */
plus( number: BigInteger ): BigInteger;
/** Alias for the subtract method. */
minus( number: number ): BigInteger;
/** Alias for the subtract method. */
minus( number: BigInteger ): BigInteger;
/** Performs subtraction. */
subtract( number: number ): BigInteger;
/** Performs subtraction. */
subtract( number: BigInteger ): BigInteger;
/** Performs multiplication. */
multiply( number: number ): BigInteger;
/** Performs multiplication. */
multiply( number: BigInteger ): BigInteger;
/** Alias for the multiply method. */
times( number: number ): BigInteger;
/** Alias for the multiply method. */
times( number: BigInteger ): BigInteger;
/** Performs integer division, disregarding the remainder. */
divide( number: number ): BigInteger;
/** Performs integer division, disregarding the remainder. */
divide( number: BigInteger ): BigInteger;
/** Alias for the divide method. */
over( number: number ): BigInteger;
/** Alias for the divide method. */
over( number: BigInteger ): BigInteger;
/** Performs exponentiation. If the exponent is less than 0, pow returns 0. bigInt.zero.pow(0) returns 1. */
pow( number: number ): BigInteger;
/** Performs exponentiation. If the exponent is less than 0, pow returns 0. bigInt.zero.pow(0) returns 1. */
pow( number: BigInteger ): BigInteger;
/** Adds one to the number. */
next(): BigInteger;
/** Subtracts one from the number. */
prev(): BigInteger;
/** Performs division and returns the remainder, disregarding the quotient. The sign of the remainder will match the sign of the dividend. */
mod( number: number ): BigInteger;
/** Performs division and returns the remainder, disregarding the quotient. The sign of the remainder will match the sign of the dividend. */
mod( number: BigInteger ): BigInteger;
/** Performs division and returns an object with two properties: quotient and remainder. The sign of the remainder will match the sign of the dividend. */
divmod( number: number ): { quotient: BigInteger; remainder: BigInteger };
/** Performs division and returns an object with two properties: quotient and remainder. The sign of the remainder will match the sign of the dividend. */
divmod( number: BigInteger ): { quotient: BigInteger; remainder: BigInteger };
/** Checks if the first number is greater than the second. */
greater( number: number ): boolean;
/** Checks if the first number is greater than the second. */
greater( number: BigInteger ): boolean;
/** Checks if the first number is greater than or equal to the second. */
greaterOrEquals( number: number ): boolean;
/** Checks if the first number is greater than or equal to the second. */
greaterOrEquals( number: BigInteger ): boolean;
/** Checks if the first number is lesser than the second. */
lesser( number: number ): boolean;
/** Checks if the first number is lesser than the second. */
lesser( number: BigInteger ): boolean;
/** Checks if the first number is less than or equal to the second. */
lesserOrEquals( number: number ): boolean;
/** Checks if the first number is less than or equal to the second. */
lesserOrEquals( number: BigInteger ): boolean;
/** Returns true if the number is even, false otherwise. */
isEven(): boolean;
/** Returns true if the number is odd, false otherwise. */
isOdd(): boolean;
/** Return true if the number is positive, false otherwise. Returns true for 0 and false for -0. */
isPositive(): boolean;
/** Returns true if the number is negative, false otherwise. Returns false for 0 and true for -0. */
isNegative(): boolean;
/**
* Performs a comparison between two numbers. If the numbers are equal, it returns 0.
* If the first number is greater, it returns 1. If the first number is lesser, it returns -1.
*/
compare( number: number ): BigInteger;
/**
* Performs a comparison between two numbers. If the numbers are equal, it returns 0.
* If the first number is greater, it returns 1. If the first number is lesser, it returns -1.
*/
compare( number: BigInteger ): BigInteger;
/** Performs a comparison between the absolute value of two numbers. */
compareAbs( number: number ): BigInteger;
/** Performs a comparison between the absolute value of two numbers. */
compareAbs( number: BigInteger ): BigInteger;
/** Checks if two numbers are equal. */
equals( number: number ): boolean;
/** Checks if two numbers are equal. */
equals( number: BigInteger ): boolean;
/** Checks if two numbers are not equal. */
notEquals( number: number ): boolean;
/** Checks if two numbers are not equal. */
notEquals( number: BigInteger ): boolean;
/** Converts a bigInt into a native Javascript number. Loses precision for numbers outside the range. */
toJSNumber(): number;
/** Converts a bigInt to a string. */
toString(): string;
/** Converts a bigInt to a native Javascript number. This override allows you to use native arithmetic operators without explicit conversion. */
valueOf(): number;
}
interface BigIntegerStatic {
/** Equivalent to bigInt(1) */
one: BigInteger;
/** Equivalent to bigInt(0) */
zero: BigInteger;
/** Equivalent to bigInt(-1) */
minusOne: BigInteger;
/** Equivalent to bigInt(0) */
(): BigInteger;
/** Parse a Javascript number into a bigInt */
( number: number ): BigInteger;
/** Parse a string into a bigInt */
( string: string ): BigInteger;
/** no-op */
( bigInt: BigInteger ): BigInteger;
}
declare var bigInt: BigIntegerStatic;
declare module "BigInteger" {
export = bigInt;
}