Packageorg.granite.math
Classpublic final class Long
ImplementsBigNumber

An ActionScript3 equivalent to the signed 64bits long type in Java. All arithmetic operations are provided, as well as bitwise, bit shift and comparison operator equivalents.

This class provides externalization methods that are meant to be used with specific GraniteDS serialization mechanisms. Its main purpose is to give a reliable serialization behavior between ActionScript3 and Java long type: standard serialization uses the ActionScript3 Number type, with possible lose of precision.

See also

BigInteger
BigDecimal


Public Properties
 PropertyDefined by
  highBits : uint
[read-only] The high 32bits of this Long as an uint.
Long
  lowBits : uint
[read-only] The low 32bits of this Long as an uint.
Long
  sign : int
[read-only] The sign of this Long as an int, ie: -1, 0 or 1 as the value of this Long is negative, zero or positive.
Long
Public Methods
 MethodDefined by
  
Long(value:* = null, radix:int = 10)
Constructs a new Long instance according to the supplied parameters.
Long
  
abs():Long
Returns a Long whose value is the absolute value of this Long.
Long
  
add(b:*):Long
Returns a Long whose value is (this + b), with a possible overflow (silently ignored, as in primitive operations).
Long
  
and(b:*):Long
Returns (this & b) (bitwise AND).
Long
  
clearBit(index:int):Long
Returns a Long whose value is equivalent to this Long with the designated bit cleared: computes (this & ~(1 << n)).
Long
  
compareTo(b:Long):int
Compares this Long with the specified Long.
Long
  
divide(b:*):Long
Returns a Long whose value is (this / b).
Long
  
divideAndRemainder(b:*):Array
Returns an array of two Long containing (this / b) followed by (this % b).
Long
  
equals(b:*):Boolean
Compares this Long with the specified object for equality.
Long
  
leftShift(value:uint):Long
Returns (this << b) (bitwise left shift).
Long
  
multiply(b:*):Long
Returns a Long whose value is (this * b), with a possible overflow (silently ignored, as in primitive operations).
Long
  
Returns a Long whose value is (-this).
Long
  
not():Long
Returns (~this) (bitwise NOT).
Long
  
or(b:*):Long
Returns (this | b) (bitwise OR).
Long
  
Returns a Long whose value is (this % b).
Long
  
rightShift(value:uint, unsigned:Boolean = false):Long
Returns (this >> b) (bitwise right shift).
Long
  
setBit(index:int):Long
Returns a Long whose value is equivalent to this Long with the designated bit set: computes (this | (1 << n)).
Long
  
subtract(b:*):Long
Returns a Long whose value is (this - b), with a possible overflow (silently ignored, as in primitive operations).
Long
  
testBit(index:int):Boolean
Returns true if and only if the designated bit is set: computes ((this & (1 << n)) != 0).
Long
  
toHexString():String
Returns a string representation of this Long as an unsigned integer in base 16.
Long
  
toInt():int
Converts this Long to an int: it is equivalent to int(this.lowBits) with a possible lose of precision and a different sign than the original value.
Long
  
toNumber():Number
Converts this Long to a Number (with a possible lose of precision).
Long
  
toString(radix:int = 10):String
Returns a string representation of this Long as signed integer in the specified radix.
Long
  
xor(b:*):Long
Returns (this ^ b) (bitwise XOR).
Long
Public Constants
 ConstantDefined by
  MAX_VALUE : Long
[static]
Long
  MIN_VALUE : Long
[static]
Long
  ONE : Long
[static] The Long constant one.
Long
  TEN : Long
[static] The Long constant ten.
Long
  ZERO : Long
[static] The Long constant zero.
Long
Property detail
highBitsproperty
highBits:uint  [read-only]

The high 32bits of this Long as an uint.

Implementation
    public function get highBits():uint
lowBitsproperty 
lowBits:uint  [read-only]

The low 32bits of this Long as an uint.

Implementation
    public function get lowBits():uint
signproperty 
sign:int  [read-only]

The sign of this Long as an int, ie: -1, 0 or 1 as the value of this Long is negative, zero or positive.

Implementation
    public function get sign():int
Constructor detail
Long()constructor
public function Long(value:* = null, radix:int = 10)

Constructs a new Long instance according to the supplied parameters.

The value parameter may be a String representation of an integer, a int primitive value, a Number or even another Long:

Parameters
value:* (default = null) — the value to be assigned to the new Long.
 
radix:int (default = 10) — the radix (2 <= radix <= 36) to be used for string conversion (ignored if the value parameter isn't a string).

Throws
NumberFormatError — if the value parameter is an invalid String representation or it doesn't fit into a signed 64bits type.
 
IllegalArgumentError — if the value parameter is not one of the supported types or if it is Number.NaN, Number.POSITIVE_INFINITY or Number.NEGATIVE_INFINITY.
Method detail
abs()method
public function abs():Long

Returns a Long whose value is the absolute value of this Long.

Returns
Long — the absolute value of this Long.
add()method 
public function add(b:*):Long

Returns a Long whose value is (this + b), with a possible overflow (silently ignored, as in primitive operations).

The b parameter may be of any of the supported types as specified in the Long constructor documentation (a radix of 10 is assumed for String representations).

Parameters
b:* — the value to be added to this Long.

Returns
Long(this + b).

Throws
NumberFormatError — if the b parameter is an invalid String representation (for radix 10).
 
IllegalArgumentError — if the b parameter is not one of the supported types or if it is Number.NaN, Number.POSITIVE_INFINITY or Number.NEGATIVE_INFINITY.
and()method 
public function and(b:*):Long

Returns (this & b) (bitwise AND).

Parameters
b:* — the other operand used in the operation (may be of any type accepted by the Long constructor).

Returns
Long(this & b).
clearBit()method 
public function clearBit(index:int):Long

Returns a Long whose value is equivalent to this Long with the designated bit cleared: computes (this & ~(1 << n)).

Parameters
index:int — the index of bit to clear.

Returns
Longthis & ~(1 << n)

Throws
ArithmeticError — if index is negative or greater than 63.
compareTo()method 
public function compareTo(b:Long):int

Compares this Long with the specified Long. This method is provided in preference to individual methods for each of the six boolean comparison operators (<, ==, >, <=, !=, >=). The suggested idiom for performing these comparisons is: (x.compareTo(y) <op> 0), where <op> is one of the six comparison operators.

Parameters
b:Long — the Long to which this Long is to be compared.

Returns
int — -1, 0 or 1 as this Long is numerically less than, equal to, or greater than b.
divide()method 
public function divide(b:*):Long

Returns a Long whose value is (this / b).

The b parameter may be of any of the supported types as specified in the Long constructor documentation (a radix of 10 is assumed for String representations).

Parameters
b:* — the value by which this Long is to be divided.

Returns
Long(this / b).

Throws
ArithmeticError — if the b parameter is equals to 0.
 
NumberFormatError — if the b parameter is an invalid String representation (for radix 10).
 
IllegalArgumentError — if the b parameter is not one of the supported types or if it is Number.NaN, Number.POSITIVE_INFINITY or Number.NEGATIVE_INFINITY.
divideAndRemainder()method 
public function divideAndRemainder(b:*):Array

Returns an array of two Long containing (this / b) followed by (this % b).

The b parameter may be of any of the supported types as specified in the Long constructor documentation (a radix of 10 is assumed for String representations).

Parameters
b:* — the value by which this Long is to be divided, and the remainder computed.

Returns
Array — an array of two Long: the quotient (this / val) is the initial element, and the remainder (this % val) is the final element.

Throws
ArithmeticError — if the b parameter is equals to 0.
 
NumberFormatError — if the b parameter is an invalid String representation (for radix 10).
 
IllegalArgumentError — if the b parameter is not one of the supported types or if it is Number.NaN, Number.POSITIVE_INFINITY or Number.NEGATIVE_INFINITY.
equals()method 
public function equals(b:*):Boolean

Compares this Long with the specified object for equality.

The b parameter may be of any of the supported types as specified in the Long constructor documentation (a radix of 10 is assumed for String representations).

Parameters
b:* — an object to which this Long is to be compared.

Returns
Booleantrue if and only if the specified object is a Long (or convertible to a Long) whose value is numerically equal to this Long.
leftShift()method 
public function leftShift(value:uint):Long

Returns (this << b) (bitwise left shift).

Parameters
value:uint

Returns
Long(this << b).
multiply()method 
public function multiply(b:*):Long

Returns a Long whose value is (this * b), with a possible overflow (silently ignored, as in primitive operations).

The b parameter may be of any of the supported types as specified in the Long constructor documentation (a radix of 10 is assumed for String representations).

Parameters
b:* — the value to be multiplied by this Long.

Returns
Long(this * b).

Throws
NumberFormatError — if the b parameter is an invalid String representation (for radix 10).
 
IllegalArgumentError — if the b parameter is not one of the supported types or if it is Number.NaN, Number.POSITIVE_INFINITY or Number.NEGATIVE_INFINITY.
negate()method 
public function negate():Long

Returns a Long whose value is (-this).

Returns
Long(-this).
not()method 
public function not():Long

Returns (~this) (bitwise NOT).

Returns
Long(~this).
or()method 
public function or(b:*):Long

Returns (this | b) (bitwise OR).

Parameters
b:* — the other operand used in the operation (may be of any type accepted by the Long constructor).

Returns
Long(this | b).
remainder()method 
public function remainder(b:*):Long

Returns a Long whose value is (this % b).

The b parameter may be of any of the supported types as specified in the Long constructor documentation (a radix of 10 is assumed for String representations).

Parameters
b:* — the value by which this Long is to be divided, and the remainder computed.

Returns
Long(this % b).

Throws
ArithmeticError — if the b parameter is equals to 0.
 
NumberFormatError — if the b parameter is an invalid String representation (for radix 10).
 
IllegalArgumentError — if the b parameter is not one of the supported types or if it is Number.NaN, Number.POSITIVE_INFINITY or Number.NEGATIVE_INFINITY.
rightShift()method 
public function rightShift(value:uint, unsigned:Boolean = false):Long

Returns (this >> b) (bitwise right shift).

Parameters
value:uint
 
unsigned:Boolean (default = false)

Returns
Long(this >> b).
setBit()method 
public function setBit(index:int):Long

Returns a Long whose value is equivalent to this Long with the designated bit set: computes (this | (1 << n)).

Parameters
index:int — the index of bit to set.

Returns
Longthis | (1 << n)

Throws
ArithmeticError — if index is negative or greater than 63.
subtract()method 
public function subtract(b:*):Long

Returns a Long whose value is (this - b), with a possible overflow (silently ignored, as in primitive operations).

The b parameter may be of any of the supported types as specified in the Long constructor documentation (a radix of 10 is assumed for String representations).

Parameters
b:* — the value to be subtracted from this Long.

Returns
Long(this - b).

Throws
NumberFormatError — if the b parameter is an invalid String representation (for radix 10).
 
IllegalArgumentError — if the b parameter is not one of the supported types or if it is Number.NaN, Number.POSITIVE_INFINITY or Number.NEGATIVE_INFINITY.
testBit()method 
public function testBit(index:int):Boolean

Returns true if and only if the designated bit is set: computes ((this & (1 << n)) != 0).

Parameters
index:int — the index of bit to test.

Returns
Booleantrue if and only if the designated bit is set.

Throws
ArithmeticError — if index is negative or greater than 63.
toHexString()method 
public function toHexString():String

Returns a string representation of this Long as an unsigned integer in base 16.

Returns
String — a string representation of this Long as an unsigned integer in base 16.
toInt()method 
public function toInt():int

Converts this Long to an int: it is equivalent to int(this.lowBits) with a possible lose of precision and a different sign than the original value.

Returns
int — this Long converted to an int.
toNumber()method 
public function toNumber():Number

Converts this Long to a Number (with a possible lose of precision).

Returns
Number — this Long converted to a Number.
toString()method 
public function toString(radix:int = 10):String

Returns a string representation of this Long as signed integer in the specified radix.

Parameters
radix:int (default = 10) — the radix to be used (2 <= radix <= 36).

Returns
String — a string representation of this Long as signed integer in the specified radix.

Throws
IllegalArgumentError — if the specified radix is out of supported range.
xor()method 
public function xor(b:*):Long

Returns (this ^ b) (bitwise XOR).

Parameters
b:* — the other operand used in the operation (may be of any type accepted by the Long constructor).

Returns
Long(this ^ b).
Constant detail
MAX_VALUEconstant
public static const MAX_VALUE:Long
MIN_VALUEconstant 
public static const MIN_VALUE:Long
ONEconstant 
public static const ONE:Long

The Long constant one.

TENconstant 
public static const TEN:Long

The Long constant ten.

ZEROconstant 
public static const ZERO:Long

The Long constant zero.