Debian Codegraph @

doc/IntObj.3

raw
1 '\"
2 '\" Copyright (c) 1996-1997 Sun Microsystems, Inc.
3 '\"
4 '\" See the file "license.terms" for information on usage and redistribution
5 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6 '\"
7 .TH Tcl_IntObj 3 8.5 Tcl "Tcl Library Procedures"
8 .so man.macros
9 .BS
10 .SH NAME
11 Tcl_NewIntObj, Tcl_NewLongObj, Tcl_NewWideIntObj, Tcl_SetIntObj, Tcl_SetLongObj, Tcl_SetWideIntObj, Tcl_GetIntFromObj, Tcl_GetLongFromObj, Tcl_GetWideIntFromObj, Tcl_NewBignumObj, Tcl_SetBignumObj, Tcl_GetBignumFromObj, Tcl_TakeBignumFromObj \- manipulate Tcl values as integers
12 .SH SYNOPSIS
13 .nf
14 \fB#include <tcl.h>\fR
15 .sp
16 Tcl_Obj *
17 \fBTcl_NewIntObj\fR(\fIintValue\fR)
18 .sp
19 Tcl_Obj *
20 \fBTcl_NewLongObj\fR(\fIlongValue\fR)
21 .sp
22 Tcl_Obj *
23 \fBTcl_NewWideIntObj\fR(\fIwideValue\fR)
24 .sp
25 \fBTcl_SetIntObj\fR(\fIobjPtr, intValue\fR)
26 .sp
27 \fBTcl_SetLongObj\fR(\fIobjPtr, longValue\fR)
28 .sp
29 \fBTcl_SetWideIntObj\fR(\fIobjPtr, wideValue\fR)
30 .sp
31 int
32 \fBTcl_GetIntFromObj\fR(\fIinterp, objPtr, intPtr\fR)
33 .sp
34 int
35 \fBTcl_GetLongFromObj\fR(\fIinterp, objPtr, longPtr\fR)
36 .sp
37 int
38 \fBTcl_GetWideIntFromObj\fR(\fIinterp, objPtr, widePtr\fR)
39 .sp
40 .sp
41 \fB#include <tclTomMath.h>\fR
42 .sp
43 Tcl_Obj *
44 \fBTcl_NewBignumObj\fR(\fIbigValue\fR)
45 .sp
46 \fBTcl_SetBignumObj\fR(\fIobjPtr, bigValue\fR)
47 .sp
48 int
49 \fBTcl_GetBignumFromObj\fR(\fIinterp, objPtr, bigValue\fR)
50 .sp
51 int
52 \fBTcl_TakeBignumFromObj\fR(\fIinterp, objPtr, bigValue\fR)
53 .sp
54 int
55 \fBTcl_InitBignumFromDouble\fR(\fIinterp, doubleValue, bigValue\fR)
56 .SH ARGUMENTS
57 .AS Tcl_WideInt doubleValue in/out
58 .AP int intValue in
59 Integer value used to initialize or set a Tcl value.
60 .AP long longValue in
61 Long integer value used to initialize or set a Tcl value.
62 .AP Tcl_WideInt wideValue in
63 Wide integer value used to initialize or set a Tcl value.
64 .AP Tcl_Obj *objPtr in/out
65 For \fBTcl_SetIntObj\fR, \fBTcl_SetLongObj\fR, \fBTcl_SetWideIntObj\fR,
66 and \fBTcl_SetBignumObj\fR, this points to the value in which to store an
67 integral value. For \fBTcl_GetIntFromObj\fR, \fBTcl_GetLongFromObj\fR,
68 \fBTcl_GetWideIntFromObj\fR, \fBTcl_GetBignumFromObj\fR, and
69 \fBTcl_TakeBignumFromObj\fR, this refers to the value from which
70 to retrieve an integral value.
71 .AP Tcl_Interp *interp in/out
72 When non-NULL, an error message is left here when integral value
73 retrieval fails.
74 .AP int *intPtr out
75 Points to place to store the integer value retrieved from \fIobjPtr\fR.
76 .AP long *longPtr out
77 Points to place to store the long integer value retrieved from \fIobjPtr\fR.
78 .AP Tcl_WideInt *widePtr out
79 Points to place to store the wide integer value retrieved from \fIobjPtr\fR.
80 .AP mp_int *bigValue in/out
81 Points to a multi-precision integer structure declared by the LibTomMath
82 library.
83 .AP double doubleValue in
84 Double value from which the integer part is determined and
85 used to initialize a multi-precision integer value.
86 .BE
87 .SH DESCRIPTION
88 .PP
89 These procedures are used to create, modify, and read Tcl values
90 that hold integral values.
91 .PP
92 The different routines exist to accommodate different integral types in C
93 with which values might be exchanged. The C integral types for which Tcl
94 provides value exchange routines are \fBint\fR, \fBlong int\fR,
95 \fBTcl_WideInt\fR, and \fBmp_int\fR. The \fBint\fR and \fBlong int\fR types
96 are provided by the C language standard. The \fBTcl_WideInt\fR type is a
97 typedef defined to be whatever signed integral type covers at least the
98 64-bit integer range (-9223372036854775808 to 9223372036854775807). Depending
99 on the platform and the C compiler, the actual type might be
100 \fBlong int\fR, \fBlong long int\fR, \fB__int64\fR, or something else.
101 The \fBmp_int\fR type is a multiple-precision integer type defined
102 by the LibTomMath multiple-precision integer library.
103 .PP
104 The \fBTcl_NewIntObj\fR, \fBTcl_NewLongObj\fR, \fBTcl_NewWideIntObj\fR,
105 and \fBTcl_NewBignumObj\fR routines each create and return a new
106 Tcl value initialized to the integral value of the argument. The
107 returned Tcl value is unshared.
108 .PP
109 The \fBTcl_SetIntObj\fR, \fBTcl_SetLongObj\fR, \fBTcl_SetWideIntObj\fR,
110 and \fBTcl_SetBignumObj\fR routines each set the value of an existing
111 Tcl value pointed to by \fIobjPtr\fR to the integral value provided
112 by the other argument. The \fIobjPtr\fR argument must point to an
113 unshared Tcl value. Any attempt to set the value of a shared Tcl value
114 violates Tcl's copy-on-write policy. Any existing string representation
115 or internal representation in the unshared Tcl value will be freed
116 as a consequence of setting the new value.
117 .PP
118 The \fBTcl_GetIntFromObj\fR, \fBTcl_GetLongFromObj\fR,
119 \fBTcl_GetWideIntFromObj\fR, \fBTcl_GetBignumFromObj\fR, and
120 \fBTcl_TakeBignumFromObj\fR routines attempt to retrieve an integral
121 value of the appropriate type from the Tcl value \fIobjPtr\fR. If the
122 attempt succeeds, then \fBTCL_OK\fR is returned, and the value is
123 written to the storage provided by the caller. The attempt might
124 fail if \fIobjPtr\fR does not hold an integral value, or if the
125 value exceeds the range of the target type. If the attempt fails,
126 then \fBTCL_ERROR\fR is returned, and if \fIinterp\fR is non-NULL,
127 an error message is left in \fIinterp\fR. The \fBTcl_ObjType\fR
128 of \fIobjPtr\fR may be changed to make subsequent calls to the
129 same routine more efficient. Unlike the other functions,
130 \fBTcl_TakeBignumFromObj\fR may set the content of the Tcl value
131 \fIobjPtr\fR to an empty string in the process of retrieving the
132 multiple-precision integer value.
133 .PP
134 The choice between \fBTcl_GetBignumFromObj\fR and
135 \fBTcl_TakeBignumFromObj\fR is governed by how the caller will
136 continue to use \fIobjPtr\fR. If after the \fBmp_int\fR value
137 is retrieved from \fIobjPtr\fR, the caller will make no more
138 use of \fIobjPtr\fR, then using \fBTcl_TakeBignumFromObj\fR
139 permits Tcl to detect when an unshared \fIobjPtr\fR permits the
140 value to be moved instead of copied, which should be more efficient.
141 If anything later in the caller requires
142 \fIobjPtr\fR to continue to hold the same value, then
143 \fBTcl_GetBignumFromObj\fR must be chosen.
144 .PP
145 The \fBTcl_InitBignumFromDouble\fR routine is a utility procedure
146 that extracts the integer part of \fIdoubleValue\fR and stores that
147 integer value in the \fBmp_int\fR value \fIbigValue\fR.
148 .SH "SEE ALSO"
149 Tcl_NewObj, Tcl_DecrRefCount, Tcl_IncrRefCount, Tcl_GetObjResult
150 .SH KEYWORDS
151 integer, integer value, integer type, internal representation, value,
152 value type, string representation