.\" -* nroff -*-
.\" Copyright (c) 2005 by Kevin B. Kenny. All rights reserved.
.\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
'\" RCS: @(#) $Id: BigInt.3,v 1.1.2.3 2004/12/13 21:23:10 kennykb Exp $
'\"
.so man.macros
.TH Tcl_BigInt 3 8.5 Tcl "Tcl Library Procedures"
.BS
.SH NAME
Tcl_BigIntFromInt, Tcl_BigIntFromWideInt, Tcl_FreeBigInt \- manipulate arbitrary precision integers.
.SH Synopsis
.nf
\fB#include <tcl.h>\fR
.sp
Tcl_BigInt
\fBTcl_BigIntFromInt\fR(\fIintVal\fR)
.sp
Tcl_BigInt
\fBTcl_BigIntFromWideInt\fR(\fIwideVal\fR)
.sp
Tcl_BigInt
\fBTcl_CopyBigInt\fR(\fIbigVal\fR)
.sp
void
\fBTcl_FreeBigInt\fR(\fIbigVal\fR)
.sp
int
\fBTcl_BigIntIsEven\fR(\fIbigVal\fR)
.sp
int
\fBTcl_BigIntIsOdd\fR(\fIbigVal\fR)
.sp
int
\fBTcl_BigIntIsZero\fR(\fIbigVal\fR)
.sp
int
\fBTcl_BigIntIsNegative\fR(\fIbigVal\fR)
.sp
int
\fBTcl_BigIntIsPositive\fR(\fIbigVal\fR)
.sp
int
\fBTcl_BigIntIsUnit\fR(\fIbigVal\fR)
.sp
int
\fBTcl_BigIntIsOne\fR(\fIbigVal\fR)
.sp
int
\fBTcl_BigIntIsMinusOne\fR(\fIbigVal\fR)
.sp
int
\fBTcl_BigIntIsInt\fR(\fIbigVal\fR)
.sp
int
\fBTcl_BigIntIsWideInt\fR(\fIbigVal\fR
.sp
Tcl_BigInt
\fBTcl_AddBigInt\fR(\fIbigVal1\fR, \fIbigVal2\fR).sp
.sp
Tcl_BigInt
\fBTcl_SubtractBigInt\fR(\fIbigVal1\fR, \fIbigVal2\fR)
.sp
Tcl_BigInt
\fBTcl_MultiplyBigIntByNarrowInt\fR(\fIbigVal1\fR,\fInarrowVal2\fR)
.sp
Tcl_BigInt
\fBTcl_ShiftBigInt\fR(\fIbigVal\fR,\fIintVal\fR)
.SH ARGUMENTS
.AS "Tcl_NarrowInt" narrowVal2 in/out
.AP Tcl_BigInt bigVal
The arbitrary-precision integer value to use as an operand.
.AP Tcl_BigInt bigVal1
The arbitrary-precision integer value to use as the first operand of
an operation.
.AP Tcl_BigInt bigVal2
The arbitrary-precision integer value to use as the second operand of
an operation.
.AP int intVal in
The native integer value to use as an operand.
.AP Tcl_NarrowInt narrowVal2
The "narrow" integer value to use as the second operand of an operation
.AP Tcl_WideInt wideVal in
The wide integer value to use as an operand.
.BE
.SH DESCRIPTION
.PP
The procedures described in this manual entry allow a C program that
links with the Tcl library to manipulate integers of arbitrary
precision.
.PP
\fBTcl_BigIntFromInt\fR and \fBTcl_BigIntFromWideInt\fR construct
arbitrary-precision integers from native integers. Each accepts a
single argument which is an \fBint\fR or a \fBTcl_WideInt\fR
respectively, and constructs a \fBTcl_BigInt\fR that represents the
same value. The value must eventually be freed by passing it to
\fBTcl_FreeBigInt\fR.
.PP
\fBTcl_CopyBigInt\fR makes a copy of a \fBTcl_BigInt\fR (passed
as the \fIbigVal\rR argument) in newly allocated memory. The copy
is returned, and must eventually be freed by passing it to
\fBTcl_FreeBigInt\fR.
.PP
\fBTcl_FreeBigInt\fR frees a big integer value that was previously
allocated by any of the \fBTcl_BigInt\fR procedures. It accepts a single
\fIbigVal\fR argument, and frees all memory associated with it.
.PP
\fBTcl_BigIntIsEven\fR tests whether \fIbigVal\fR is even, returning
1 if it is and 0 if it isn't. Similarly \fBTcl_BigIntIsOdd\fR tests
whether \fIbigVal\fR is odd, \fBTcl_BigIntIsZero\fR tests whether it
is zero, \fBTcl_BigIntIsNegative\fR tests whether it is negative,
\fBTcl_BigIntIsPositive\fR tests whether it is strictly positive,
\fBTcl_BigIntIsUnit\fR tests whether it is either 1 or -1,
\fBTcl_BigIntIsOne\fR tests whether it is equal to 1, and
\fBTcl_BigIntIsMinusOne\fR tests whether it is equal to -1.
.PP
\fBTcl_BigIntIsInt\fR returns 1 if \fIbigVal\fR will fit in a native
\fBint\fR, and 0 if it is too big to fit. Similarly,
\fBTcl_BigIntIsWideInt\fR returns 1 if \fIbigVal\fR will fit in a
\fBTcl_WideInt\fR and 0 otherwise.
.PP
\fBTcl_GetIntFromBigInt\fR returns the value of \fIbigVal\fR converted
to a native \fBint\fR. \fBTcl_GetWideIntFromBigInt\fR returns the
value of \fIbigVal\fR converted to a \fBTcl_WideInt\fR. Both
functions ignore overflow, returning the least significant bits of
a value that is too large to fit. Use \fBTcl_BigIntIsInt\fR or
\fBTcl_BigIntIsWide\fR to check the size of an integer before
conversion if overflow will be a problem.
.PP
\fBTcl_AddBigInt\fR and \fBTcl_SubtractBigInt\fR, respectively,
add and subtract arbitrary-precision integers. \fIbigVal1\fR is the
left operand of these operations, and \fIbigVal2\fR is the right
operand. The result is returned from the functions, and must
eventually be freed by calling \fBTcl_FreeBigInt\fR.
.PP
\fBTcl_MultiplyBigIntByNarrowInt\fR multiplies an arbitrary-precision
integer, \fIbigVal1\fR, by a narrow integer, \fInarrowVal2\fR. The
width of the narrow integer is platform dependent; the function is
useful chiefly for multiplying a large integer by a small constant
such as 2 or 10. The result returned must eventually be freed by
calling \fBTcl_FreeBigInt\fR.
.PP
\fBTcl_ShiftBigInt\fR multiplies an arbitrary-precision integer,
\fIbigVal\fR by a power of two. The exponent of two is passed as
\fIintVal\fR. Multiplication by a negative power of two is possible,
and truncates toward negative infinity. The result returned must
eventually be freed by calling \fBTcl_FreeBigInt\fR.
.SH "SEE ALSO"
Tcl_IntObj
.SH KEYWORDS
integer, wide, integer type, arbitrary precision, multiple precision, bignum