|
[Contents] [Previous] [Next] [Last]
Chapter 15
Long Long (64 Bit) Integers
This chapter describes the global functions you use to perform 64 Bit Integer
operations. The functions define a portable API that may be reliably used
in any environment. Most of the 64 bit integer operations are implemented
as macros. The specific implementation of the macros are dependent on whether
the compiler for the target platform supports 64 bit integers.
For a specific target platform, if 64 bit integers are supported for
that platform, define HAVE_LONG_LONG at compile time.
Where 64 bit integers are desired, use of NSPR's implementation is recommended
to ensure cross platform compatibility.
64 Bit Integer Types
NSPR provides two 64 Bit Integer Types.
These types are PRInt64 and
PRUint64 .
64 Bit Integer Functions
The API defined for the 64 bit integer functions is consistent across all
supported platforms.
-
Initialization and Limits
-
LL_MaxInt
-
LL_MinInt
-
LL_Zero
-
LL_INIT
-
Relational Operators
-
LL_IS_ZERO
-
LL_EQ
-
LL_NE
-
LL_GE_ZERO
-
LL_CMP
-
LL_UCMP
-
Logical Operators
-
LL_AND
-
LL_OR
-
LL_XOR
-
LL_OR2
-
LL_NOT
-
Arithmetic Operators
-
LL_NEG
-
LL_ADD
-
LL_SUB
-
LL_MUL
-
LL_DIV
-
LL_MOD
-
Shift Operators
-
LL_SHL
-
LL_SHR
-
LL_USHR
-
LL_ISHL
-
Conversion Operators
-
LL_L2I
-
LL_L2UI
-
LL_L2F
-
LL_L2D
-
LL_I2L
-
LL_UI2L
-
LL_F2L
-
LL_D2L
-
LL_UDIVMOD
Initialization and Limits
Long Long initialization functions initialize a PRInt64 data item. The
limit functions initialize a 64 bit integer to the highest or lowest possible
value for a 64 bit integer.
LL_MaxInt
Returns the a 64 bit integer whose value is the largest possible value.
Syntax
#include <prlong.h>
PRInt64 LL_MaxInt( void );
Parameter
The function has no parameter.
Returns
The largest possible value for a 64 bit integer.
Description
Return the largest possible value for a 64 bit integer.
LL_MinInt
Returns the a 64 bit integer whose value is the least possible value.
Syntax
#include <prlong.h>
PRInt64 LL_MinInt( void );
Parameter
The function has no parameter:
Returns
The smallest possible value for a 64 bit integer.
Description
Return the smallest possible value for a 64 bit integer.
LL_Zero
Return a PRInt64 value of zero.
Syntax
#include <prlong.h>
PRInt64 LL_Zero( void );
Parameter
The function has no parameter:
Returns
zero.
Description
LL_INIT
Initialize a 64 bit integer.
Syntax
#include <prlong.h>
PRInt64 LL_INIT(PRInt32 hi, PRInt32 lo );
Parameter
The function has the following parameters:
hi
|
The most significant 32 bit part of the
64 bit integer |
lo
|
The least significant 32 bit part of the 64 bit integer |
Returns
A 64 bit integer containing the initialized value.
Description
LL_INIT uses two 32 bit arguments: hi and lo to assemble a 64 bit integer.
Relational Operators
Note that the relational operators are implemented as macros. The return
value is platform dependent that should be treated as an int. Make no other
assumptions about its value.
LL_IS_ZERO
Evaluate a 64 bit integer for zero.
Syntax
#include <prlong.h>
int LL_IS_ZERO(
PRInt64 a );
Parameter
The function has the following parameter:
a
|
A 64 bit integer to be evaluated for zero. |
Returns
Non-zero when a is equal to zero; zero when a is not equal
to zero.
Description
LL_IS_ZERO evaluates the argument for zero.
LL_EQ
Compare two 64 bit integers for equality.
Syntax
#include <prlong.h>
int LL_EQ(
PRInt64 a,
PRInt64 b);
Parameter
The function has the following parameter:
a
|
First comparand. |
b
|
Second comparand. |
Returns
Non-zero when a is equal to b, otherwise zero.
Description
The first parameter, a is compared to the second b.
LL_NE
Compare two 64 bit integers for inequality.
Syntax
#include <prlong.h>
int LL_NE(
PRInt64 a,
PRInt64 b);
Parameter
The function has the following parameter:
a
|
First comparand. |
b
|
Second comparand. |
Returns
Non-zero when a is not equal to b, otherwise zero.
Description
The first comparand, a, is compared to the second comparand, b. The result
is non-zero if the two comparands are not equal.
LL_GE_ZERO
Evaluate a 64 bit integer for greater than or equal to zero.
Syntax
#include <prlong.h>
int LL_GE_ZERO(
PRInt64 a );
Parameter
The function has the following parameter:
a
|
A 64 bit integer to be evaluated . |
Returns
Non-zero when a is greater than or equal to zero, otherwise zero.
Description
Evaluates the parameter for greater than or equal to zero.
LL_CMP
Algebraically compare two 64 bit integers
Syntax
#include <prlong.h>
int LL_CMP(
PRInt64 a,
operator,
PRInt64 b);
Parameter
The function has the following parameter:
a
|
First comparand |
operator |
A comparison operator. |
b
|
Second comparand |
Operator is any valid C comparison operator.
Returns
Non-zero when a compared to b using operator is true, otherwise
zero.
Description
LL_CMP algebraically compares a to b according to operand.
Example
PRInt64 foo = LL_INIT( 0, 1 );
PRInt64 bar = LL_INIT( 0, 2 );
if ( LL_CMP( foo, <, bar ))
DoIt(); /* This gets called */
LL_UCMP
Logically compare two 64 bit integers.
Syntax
#include <prlong.h>
LL_UCMP(
PRUint64 a,
operator,
PRUint64 b);
Parameter
The function has the following parameter:
a
|
First comparand |
operator |
A comparison operator. |
b
|
Second comparand |
Returns
Non-zero when a compared to b using operator is true,
otherwise zero.
Description
LL_UCMP logically compares a to b according to operand.
Example
PRInt64 foo = LL_INIT( -1, 1 );
PRInt64 bar = LL_INIT( 0, 2 );
if ( LL_UCMP( foo, >=, bar ))
DoIt(); /* This gets called */
Logical Operators
The logical operators are implemented as macros. For each logical operator,
a result argument will contain the result of the logical operation. The
logical operators may evaluate to different results on different platforms,
therefore the result of the logical operator macros should not be used.
LL_AND
Apply logical AND to 64 bit integer operands
Syntax
#include <prlong.h>
void LL_AND(PRInt64 r, PRInt64 a, PRInt64 b);
Parameter
The function has the following parameter:
r
|
The result value |
a
|
Operand to and |
b
|
Operand to and |
Returns
void.
Description
LL_AND performs a logical and on operands a and b yielding
result r.
LL_OR
Apply logical OR to 64 bit integer operands
Syntax
#include <prlong.h>
void LL_OR(PRInt64 r, PRInt64 a, PRInt64 b);
Parameter
The function has the following parameter:
r
|
A pointer to the result value. |
a
|
Operand to and |
b
|
Operand to and |
Returns
void.
Description
Operand a is logically or'd with operand b yielding r.
LL_XOR
Apply logical Exclusive OR (xor) to 64 bit integer operands
Syntax
#include <prlong.h>
void LL_XOR(PRInt64 r, PRInt64 a, PRInt64 b);
Parameter
The function has the following parameter:
r
|
The result value. |
a
|
Operand to and |
b
|
Operand to and |
Returns
void
Description
Operand a is xor'd with operand b yielding r.
LL_OR2
Apply logical OR to 64 bit integers
Syntax
#include <prlong.h>
void LL_OR2(PRInt64 r, PRInt64 a);
Parameter
The function has the following parameter:
r
|
The result value. |
| a |
operand |
Returns
void
Description
Operand a is logically OR'd with r. The result is placed
in r.
LL_NOT
Invert bits in a 64 bit integer
Syntax
#include <prlong.h>
void LL_NOT(PRInt64 r, PRInt64 a);
Parameter
The function has the following parameter:
a
|
A pointer to the value to increment. |
Returns
void
Description
All bits in operand a are inverted and the result is placed in r.
Arithmetic Operators
The arithmetic operators are implemented as macros. For each arithmetic
operator, a result argument contains the result of the arithmetic operation.
The arithmetic operators may evaluate to different results on different
platforms, therefore the result of the logical operator macros should not
be used.
LL_NEG
Negate a 64 bit integer.
Syntax
#include <prlong.h>
void LL_NEG( PRInt64 r, PRInt64 a);
Parameter
The function has the following parameter:
r
|
The result. |
a
|
Operand to be negated |
Returns
void
Description
The operand a is negated. The result is placed in r.
LL_ADD
Add 64 bit integers.
Syntax
#include <prlong.h>
void LL_ADD(PRInt64 r, PRInt64 a, PRInt64 b);
Parameter
The function has the following parameter:
r
|
The result value. |
a
|
First operand |
b
|
Second operand |
Returns
void
Description
Operands a and b are arithmetically added. The result is placed in r.
LL_SUB
Syntax
#include <prlong.h>
void LL_SUB(PRInt64 r, PRInt64 a, PRInt64 b);
Parameter
The function has the following parameter:
r
|
The result value. |
a
|
First operand |
b
|
Second operand |
Returns
void
Description
Operand b is subtracted from operand a. The result is placed in r.
LL_MUL
Multiply 64 bit integers.
Syntax
#include <prlong.h>
void LL_MUL(PRInt64 r, PRInt64 a, PRInt64 b);
Parameter
The function has the following parameter:
r
|
The result value. |
a
|
First operand |
b
|
Second operand |
Returns
void
Description
Operand b is multiplied by operand a. The result is placed in r.
LL_DIV
Divide a 64 bit integer by another 64 bit integer.
Syntax
#include <prlong.h>
void LL_DIV(PRInt64 r, PRInt64 a, PRInt64 b);
Parameter
The function has the following parameter:
r
|
The result value. |
a
|
First operand |
b
|
Second operand |
Returns
Description
Operand a is divided by operand b. The result is placed in r.
LL_MOD
Modulo divide a 64 bit integer by another 64 bit integer.
Syntax
#include <prlong.h>
void LL_MOD(PRInt64 r, PRInt64 a, PRInt64 b);
Parameter
The function has the following parameter:
r
|
64 bit integer result. |
a
|
64 bit integer dividend |
b
|
64 bit integer divisor |
Returns
void
Description
Operand a is divided by operand b. The remainder is placed in r.
Shift Operators
The shift operators are implemented as macros. For each shift operator,
a result argument contains the result of the shift operation. The shift
operators may evaluate to different results on different platforms, therefore
the result of the logical operator macros should not be used.
LL_SHL
Shift a 64 bit integer to the left
Syntax
#include <prlong.h>
void LL_SHL(PRInt64 r, PRInt64 a, PRInt32 b);
Parameter
The function has the following parameter:
r
|
The result value. |
a
|
First operand |
b
|
Second operand |
Returns
void
Description
Operand a is arithmetically shifted left b bits. The result
is placed in r.
LL_SHR
Shift a 64 bit integer to the right
Syntax
#include <prlong.h>
void LL_SHL(PRInt64 r, PRInt64 a, PRInt32 b);
Parameter
The function has the following parameter:
r
|
The result value. |
a
|
First operand |
b
|
Second operand |
Returns
void
Description
Operand a is cast to a PRInt64 and arithmetically shifted right b bits.
The result is placed in r.
LL_USHR
Logically right shift a 64 bit integer
Syntax
#include <prlong.h>
void LL_USHR(PRInt64 r, PRInt64 a, PRInt32 b);
Parameter
The function has the following parameter:
Returns
void
Description
Operand a is logically shifted right b bits. The result is
placed in r.
LL_ISHL
Shift a 64 bit integer to the left
Syntax
#include <prlong.h>
LL_SHL(
PRInt64 r,
PRInt64 a,
PRInt32 b);
Parameter
The function has the following parameter:
r
|
The result value. |
a
|
First operand |
b
|
Second operand |
Returns
void
Description
Operand a is arithmetically shifted left b bits. The result
is placed in r.
Conversion Operators
LL_L2I
Convert a 64 bit integer to a 32 bit integer
Syntax
#include <prlong.h>
void LL_L2I(PRInt32 i, PRInt64 l);
Parameter
The function has the following parameter:
i
|
32 bit integer result |
l
|
64 bit integer to be converted |
Returns
void
Description
Convert 64 bit integer l to a 32 bit integer i.
LL_L2UI
Convert 64 bit integer to unsigned 32 bit integer.
Syntax
#include <prlong.h>
void LL_L2UI(PRUint32 i, PRInt64 l);
Parameter
The function has the following parameter:
i
|
32 bit integer result |
l
|
64 bit integer to be converted |
Returns
void
Description
Operand l is converted to unsigned 32 bit integer i.
LL_L2F
Convert a 64 bit integer to a float
Syntax
#include <prlong.h>
void LL_L2F(PRUint32 f, PRInt64 l);
Parameter
The function has the following parameter:
f
|
float result |
l
|
64 bit integer to be converted |
Returns
void
Description
64 bit integer l is converted to a float f.
LL_L2D
Convert a 64 bit integer to a double
Syntax
#include <prlong.h>
void LL_L2D(PRFloat64 d, PRInt64 l);
Parameter
The function has the following parameter:
d
|
PRFloat64 result |
l
|
64 bit integer to be converted |
Returns
void
Description
64 bit integer l is converted to PRFloat64 d.
LL_I2L
Convert a 32 bit integer to a 64 bit integer.
Syntax
#include <prlong.h>
void LL_I2L(PRInt64 l, PRInt32 i);
Parameter
The function has the following parameter:
l
|
64 bit integer result |
i
|
32 bit integer to be converted |
Returns
void
Description
32 bit integer i is converted to 64 bit integer l.
LL_UI2L
Convert an unsigned 32 bit integer to a 64 bit integer.
Syntax
#include <prlong.h>
void LL_UI2L(PRInt64 l, PRUint32 i);
Parameter
The function has the following parameter:
l
|
A 64 bit result. |
i
|
A 32 bit integer |
Returns
void
Description
The argument i is converted to a 64 bit integer result, l.
LL_F2L
Convert a float to a 64 bit integer
Syntax
#include <prlong.h>
void LL_F2L(PRInt64 l, float f);
Parameter
The function has the following parameter:
l
|
64 bit integer result |
f
|
floating point number to be converted |
Returns
void
Description
Floating point number f is converted to 64 bit integer, l.
LL_D2L
Convert a PRFloat64 to a 64 bit integer.
Syntax
#include <prlong.h>
void LL_D2L(PRInt64 l, PRFloat64 d);
Parameter
The function has the following parameter:
l
|
64 bit integer result. |
d
|
PRFloat64 number to be converted. |
Returns
void
Description
PRFloat64 number d is converted to 64 bit integer l.
LL_UDIVMOD
64 bit integer divide with both remainder and quotient
Syntax
#include <prlong.h>
void LLUDIVMOD(
PRUint64 *qp,
PRUint64 *rp,
PRUint64 a,
PRUint64 b);
Parameter
The function has the following parameter:
qp
|
A pointer to an PRUint64 quotient. |
rp
|
A pointer to a PRUint64 remainder |
a
|
64 bit integer dividend |
b
|
64 bit integer divisor |
Returns
void
Description
The 64 bit integer a is divided by 64 bit integer b yielding
unsigned 64 bit integer result quotient stored at qp and 64 bit
unsigned remainder stored at rp.
[Contents] [Previous] [Next] [Last]
Last Updated: Tue Jul 14 10:24:44 PDT 1998
Copyright © 1998 Netscape
Communications Corporation
|