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