You are currently viewing a snapshot of www.mozilla.org taken on April 21, 2008. Most of this content is highly out of date (some pages haven't been updated since the project began in 1998) and exists for historical purposes only. If there are any pages on this archive site that you think should be added back to www.mozilla.org, please file a bug.



NSPR Reference
Previous     Contents     Next     


Chapter 18   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 can be used reliably in any environment. Where 64-bit integers are desired, use of NSPR's implementation is recommended to ensure cross-platform compatibility.

Most of the 64-bit integer operations are implemented as macros. The specific implementation of each macro depends 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.

64-Bit Integer Types

NSPR provides two types to represent 64-bit integers: PRInt64 and PRUint64.

64-Bit Integer Functions

The API defined for the 64-bit integer functions is consistent across all supported platforms.

Limits and Initialization
Relational Operators
Logical Operators
Arithmetic Operators
Shift Operators
Conversion Operators

Limits and Initialization

The limit and initialization functions initialize a 64-bit integer to the highest or lowest possible value for a 64-bit integer, or to zero, or create a new 64-bit integer from 32-bit parts.

LL_MaxInt
LL_MinInt
LL_Zero
LL_INIT

LL_MaxInt

Returns a 64-bit integer whose value is the largest possible value.


Syntax
#include <prlong.h>

PRInt64 LL_MaxInt( void );


Parameter
The function has no parameters.


Returns
A 64-bit integer.


Description
This function returns the largest possible value for a 64-bit integer.

LL_MinInt

Returns a 64-bit integer whose value is the least possible value.


Syntax
#include <prlong.h>

PRInt64 LL_MinInt( void );


Parameter
The function has no parameters.


Returns
A 64-bit integer.


Description
This function returns the smallest possible value for a 64-bit integer.

LL_Zero

Returns a PRInt64 value of zero.


Syntax
#include <prlong.h>

PRInt64 LL_Zero( void );


Parameter
The function has no parameters.


Returns
A PRInt64 value of zero

LL_INIT

Initializes a 64-bit integer from 32-bit parts.


Syntax
#include <prlong.h>

PRInt64 LL_INIT(
   PRInt32 hi,
   PRInt32 lo );


Parameter
The macro 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
This macro assembles the two specified 32-bit integers into a 64-bit integer.

Relational Operators

The relational operators are implemented as macros. The parameters must be PRInt64 variables predefined by the caller. The return value is platform dependent. It should be treated as an int. Make no other assumptions about its value.

The relational operators are:

LL_IS_ZERO
LL_EQ
LL_NE
LL_GE_ZERO
LL_CMP
LL_UCMP

LL_IS_ZERO

Determines whether a 64-bit integer is equal to zero.


Syntax
#include <prlong.h>

int LL_IS_ZERO ( PRInt64 a );


Parameter
The macro 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
This macro evaluates specified 64-bit integer. It returns a non-zero value if the argument is equal to zero, and returns zero if the argument is not equal to zero.

LL_EQ

Compares two 64-bit integers for equality.


Syntax
#include <prlong.h>

int LL_EQ(
    PRInt64 a,
    PRInt64 b);


Parameter
The macro has the following parameters:

a

First comparand.

b

Second comparand.


Returns
Non-zero when a is equal to b, otherwise zero.


Description
This macro compares the specified 64-bit integers. If they are equal. the function returns a non-zero value. If they are not equal, the function returns zero.

LL_NE

Compares two 64-bit integers for inequality.


Syntax
#include <prlong.h>

int LL_NE(
     PRInt64 a,
     PRInt64 b);


Parameter
The macro has the following parameters:

a

First comparand.

b

Second comparand.


Returns
Non-zero when a is not equal to b, otherwise zero.


Description
This macro compares the specified 64-bit integers. If they are not equal. the function returns a non-zero value. If they are equal, the function returns zero.

LL_GE_ZERO

Determines whether a 64-bit integer is greater than or equal to zero.


Syntax
#include <prlong.h>

int LL_GE_ZERO( PRInt64 a );


Parameter
The macro 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
This macro returns a non-zero value when the specified 64-bit integer is greater than or equal to zero. If it is less than zero, the function returns zero.

LL_CMP

Algebraically compares two signed 64-bit integers


Syntax
#include <prlong.h>

int LL_CMP(
    PRInt64 a,
    operator,
    PRInt64 b);


Parameter
The macro has the following parameters:

a

First comparand.

operator

A valid C comparison operator.

b

Second comparand.


Returns
Non-zero when a compared to b using operator is true, otherwise zero.


Description
This macro algebraically compares the specified 64-bit integers using the specified operator. If the result is true, the function returns a non-zero value. If it is not true, the function returns zero.


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 compares two unsigned 64-bit integers.


Syntax
#include <prlong.h>

LL_UCMP(
    PRUint64 a,
    operator,
    PRUint64 b);


Parameter
The macro has the following parameters:

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
This macro logically compares the specified 64-bit integers using the specified operator. If the result is true, the function returns a non-zero value. If it is not true, the function returns zero.


Example
PRUint64 foo = LL_INIT( -1, 1 );
PRUint64 bar = LL_INIT( 0, 2 );

if ( LL_UCMP( foo, =, bar ))
        DoIt(); /* This gets called */

Logical Operators

The logical operators are implemented as macros. The parameters must be PRInt64 variables predefined by the caller. For each operator, a result parameter contains the result of the operation upon return from the macro.

The logical operators are:

LL_AND
LL_OR
LL_XOR
LL_OR2
LL_NOT

LL_AND

Applies a logical AND to 64-bit integer operands


Syntax
#include <prlong.h>

void LL_AND (
   PRInt64 r,
   PRInt64 a,
   PRInt64 b);


Parameter
The macro has the following parameters:

r

The result value

a

First operand.

b

Second operand.


Returns
Nothing.


Description
This macro performs a logical AND operation on operands a and b. The result is bound to the variable r.

LL_OR

Applies a logical OR to 64-bit integer operands


Syntax
include <prlong.h>

void LL_OR (
   PRInt64 r,
   PRInt64 a,
   PRInt64 b);


Parameter
The macro has the following parameters:

r

A variable that will contain the result value.

a

First operand.

b

Second operand.


Returns
Nothing.


Description
This macro performs a logical OR operation on operands a and b. The result is bound to the variable r.

LL_XOR

Applies a logical exclusive or (XOR) to 64-bit integer operands


Syntax
#include <prlong.h>

void LL_XOR (
   PRInt64 r,
   PRInt64 a,
   PRInt64 b);


Parameter
The macro has the following parameters:

r

A variable that will contain the result value.

a

First operand.

b

Second operand.


Returns
Nothing.


Description
This macro performs a logical XOR operation on operands a and b. The result is bound to the variable r.

LL_OR2

Applies a logical OR to 64-bit integers, altering the first.


Syntax
#include <prlong.h>

void LL_OR2 (
   PRInt64 r,
   PRInt64 a);


Parameter
The macro has the following parameters:

r

The first operand and result value.

a

The second operand.


Returns
Nothing.


Description
This macro performs a logical OR operation on operands r and a. The result is bound to the variable r.

LL_NOT

Inverts the bits in a 64-bit integer


Syntax
#include <prlong.h>

void LL_NOT (
   PRInt64 r,
   PRInt64 a);


Parameter
The macro has the following parameter:

r

A variable that will contain the result value.

a

The operand.


Returns
Nothing.


Description
This macro performs a logical NOT operation on the operands a, inverting all of the bits. The result is bound to the variable r.

Arithmetic Operators

The arithmetic operators are implemented as macros.The parameters must be PRInt64 variables predefined by the caller. For each operator, a result parameter contains the result of the operation upon return from the macro.

The arithmetic operators are:

LL_NEG
LL_ADD
LL_SUB
LL_MUL
LL_DIV
LL_MOD
LL_UDIVMOD

LL_NEG

Negates a 64-bit integer.


Syntax
#include <prlong.h>

void LL_NEG ( 
   PRInt64 r,
   PRInt64 a);


Parameter
The macro has the following parameters:

r

A variable that will contain the result value.

a

Operand to be negated


Returns
Nothing.


Description
This macro negates the operand a. The result is bound to the variable r.

LL_ADD

Adds 64-bit integers.


Syntax
#include <prlong.h>

void LL_ADD (
   PRInt64 r,
   PRInt64 a,
   PRInt64 b);


Parameter
The macro has the following parameters:

r

A variable that will contain the result value.

a

First operand.

b

Second operand.


Returns
Nothing.


Description
This macro arithemetically adds the operands a and b. The result is bound to the variable r.

LL_SUB

Subtracts one 64-bit integer from another.


Syntax
#include <prlong.h>

void LL_SUB (
   PRInt64 r,
   PRInt64 a,
   PRInt64 b);


Parameter
The macro has the following parameters:

r

A variable that will contain the result value.

a

First operand.

b

Second operand.


Returns
Nothing.


Description
This macro subtracts operand b from operand a. The result is bound to the variable r.

LL_MUL

Multiplies 64-bit integers.


Syntax
#include <prlong.h>

void LL_MUL (
   PRInt64 r,
   PRInt64 a,
   PRInt64 b);


Parameter
The macro has the following parameters:

r

A variable that will contain the result value.

a

First operand.

b

Second operand.


Returns
Nothing.


Description
This macro multipies operand a and operand b. The result is bound to the variable r.

LL_DIV

Divides a 64-bit integer by another 64-bit integer and returns the quotient.


Syntax
#include <prlong.h>

void LL_DIV (
   PRInt64 r,
   PRInt64 a,
   PRInt64 b);


Parameter
The macro has the following parameters:

r

A variable that will contain the result value.

a

First operand.

b

Second operand.


Returns
Nothing.


Description
This macro divides operand a by operand b. The integer result is bound to the variable r.

LL_MOD

Divides a 64-bit integer by another 64-bit integer and returns the remainder.


Syntax
#include <prlong.h>

void LL_MOD (
   PRInt64 r,
   PRInt64 a,
   PRInt64 b);


Parameter
The macro has the following parameters:

r

A variable that will contain the result value.

a

The dividend.

b

The divisor.


Returns
Nothing.


Description
This macro divides operand a by operand b. The remainder is bound to the variable r.

LL_UDIVMOD

Divides a 64-bit integer by another 64-bit integer and returns both remainder and quotient


Syntax
#include <prlong.h>

void LL_UDIVMOD(
    PRUint64 *qp,
    PRUint64 *rp,
    PRUint64 a,
    PRUint64 b);


Parameter
The function has the following parameters:

qp

A pointer to the quotient.

rp

A pointer to the remainder.

a

The dividend.

b

The divisor.


Returns
Nothing.


Description
This macro divides operand a by operand b,. The unsigned 64-bit integer result quotient is stored at the location specified by qp. The unsigned 64-bit integer result remainder is stored at the location specified by rp.



Shift Operators

The shift operators are implemented as macros. The parameters must be variables of the proper type predefined by the caller. For each operator, a result parameter contains the result of the operation upon return from the macro.

The shift operators are:

LL_SHL
LL_SHR
LL_USHR
LL_USHL

LL_SHL

Arithmetically shifts a signed 64-bit integer to the left.


Syntax
#include <prlong.h>

void LL_SHL (
   PRInt64 r,
   PRInt64 a,
   PRInt32 b);


Parameter
The macro has the following parameters:

r

A variable that will contain the result value.

a

The operand.

b

The number of bits by which to shift the operand.


Returns
Nothing.


Description
This macro arithmetically shifts the operand a left by the number of bits specified in b. The result is bound to the variable r.

LL_SHR

Arithmetically shifts a signed 64-bit integer to the right.


Syntax
#include <prlong.h>

void LL_SHL (
   PRInt64 r,
   PRInt64 a,
   PRInt32 b);


Parameter
The macro has the following parameters:

r

A variable that will contain the result value.

a

The operand.

b

The number of bits by which to shift the operand.


Returns
Nothing.


Description
This macro arithmetically shifts the operand a right by the number of bits specified in b. The result is bound to the variable r.

LL_USHR

Logically shifts an unsigned 64-bit integer to the right.


Syntax
#include <prlong.h>

void LL_USHR (
   PRInt64 r,
   PRInt64 a,
   PRInt32 b);


Parameter
The macro has the following parameters:

r

A variable that will contain the result value.

a

The operand.

b

The number of bits by which to shift the operand.


Returns
Nothing.


Description
This macro logically shifts the operand a right by the number of bits specified in b. The result is bound to the variable r.

LL_USHL

Logically shifts an unsigned 64-bit integer to the left.


Syntax
#include <prlong.h>

LL_USHL(
    PRInt64 r,
    PRInt64 a,
    PRInt32 b);


Parameter
The macro has the following parameters:

r

A variable that will contain the result value.

a

The operand.

b

The number of bits by which to shift the operand.


Returns
Nothing.


Description
This macro logically shifts the operand a left by the number of bits specified in b. The result is bound to the variable r.

Conversion Operators

These macros convert between 64-bit integers and other numeric types. The parameters must be variables of the proper type predefined by the caller. For each operator, a result parameter contains the converted value upon return from the macro.

The conversion operators are:

LL_L2I
LL_L2UI
LL_L2F
LL_L2D
LL_I2L
LL_UI2L
LL_F2L
LL_D2L

LL_L2I

Converts a 64-bit integer to a signed 32-bit integer


Syntax
#include <prlong.h>

void LL_L2I (
   PRInt32 i,
   PRInt64 l);


Parameter
The function has the following parameters:

i

The 32-bit integer result.

l

The 64-bit integer to be converted.


Returns
Nothing.


Description
This macro converts the 64-bit integer l to the 32-bit integer i.

LL_L2UI

Converts a 64-bit integer to an unsigned 32-bit integer.


Syntax
#include <prlong.h>

void LL_L2UI (
   PRUint32 i,
   PRInt64 l);


Parameter
The function has the following parameters:

i

The unsigned 32-bit integer result.

l

The 64-bit integer to be converted.


Returns
Nothing.


Description
This macro converts the 64-bit integer l to the unsigned 32-bit integer i.

LL_L2F

Converts a 64-bit integer to a 32-bit floating point number.


Syntax
#include <prlong.h>

void LL_L2F ( 
   PRFloat32 f,
   PRInt64 l);


Parameter
The function has the following parameters:

f

The floating point result.

l

The 64-bit integer to be converted.


Returns
Nothing.


Description
This macro converts the 64-bit integer l to the floating point number f.

LL_L2D

Converts a 64-bit integer to a double (64-bit) floating point number .


Syntax
#include <prlong.h>

void LL_L2D (
   PRFloat64 d,
   PRInt64 l);


Parameter
The function has the following parameters:

d

The double floating point result.

l

The 64-bit integer to be converted.


Returns
Nothing.


Description
This macro converts the 64-bit integer l to the double floating point number d.

LL_I2L

Converts 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 parameters:

l

The 64-bit integer result.

i

The 32-bit integer to be converted.


Returns
Nothing.


Description
This macro converts the 32-bit integer i to the 64-bit integer l.

LL_UI2L

Converts 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 parameters:

l

The 64-bit result.

i

The unsigned 32-bit integer to be converted.


Returns
Nothing.


Description
This macro converts the unsigned 32-bit integer i to the 64-bit integer l.

LL_F2L

Converts a floating point number to a 64-bit integer.


Syntax
#include <prlong.h>

void LL_F2L (
   PRInt64 l,
   float f);


Parameter
The function has the following parameters:

l

The 64-bit integer result.

f

The floating point number to be converted.


Returns
Nothing.


Description
This macro converts the floating point number f to the 64-bit integer l.

LL_D2L

Converts a double floating point number to a 64-bit integer.


Syntax
#include <prlong.h>

void LL_D2L (
   PRInt64 l,
   PRFloat64 d);


Parameter
The function has the following parameters:

l

The 64-bit integer result.

d

The double floating point number to be converted.


Returns
Nothing.


Description
This macro converts the double floating point number d to the 64-bit integer l.


Previous     Contents     Next     

Last Updated May 18, 2001