## Tcl9.0.3/Tk9.0.3 Documentation > Tcl C API > Number

### Tcl/Tk Applications | Tcl Commands | Tk Commands | [incr Tcl] Package Commands | SQLite3 Package Commands | TDBC Package Commands | tdbc::mysql Package Commands | tdbc::odbc Package Commands | tdbc::postgres Package Commands | tdbc::sqlite3 Package Commands | Thread Package Commands | Tcl C API | Tk C API | [incr Tcl] Package C API | TDBC Package C API

  NAME
    Tcl_GetNumber, Tcl_GetNumberFromObj — Tcl値から数値を得る get numeric value from Tcl value
  SYNOPSIS
    #include <tcl.h>
    #include <tclTomMath.h>
    int
    Tcl_GetNumber(interp, bytes, numBytes, clientDataPtr, typePtr)
    int
    Tcl_GetNumberFromObj(interp, objPtr, clientDataPtr, typePtr)
  引数 ARGUMENTS
    Tcl_Interp *interp (出力out)
    const char *bytes (入力in)
    Tcl_Size numBytes (入力in)
    void * *clientDataPtr (出力out)
    int *typePtr (出力out)
    Tcl_Obj *objPtr (入力in)
  説明 DESCRIPTION
  SEE ALSO
  KEYWORDS

### NAME

Tcl_GetNumber, Tcl_GetNumberFromObj — Tcl値から数値を得る get numeric value from Tcl value

### SYNOPSIS

#include <tcl.h>
#include <tclTomMath.h>
int
Tcl_GetNumber(interp, bytes, numBytes, clientDataPtr, typePtr)
int
Tcl_GetNumberFromObj(interp, objPtr, clientDataPtr, typePtr)

### 引数 ARGUMENTS

Tcl_Interp *interp (出力out)
  非ヌルの時に､ 値がTclによって認識されるどのような数的形式でもない時､ 不都合情報が此処に記録される｡ When non-NULL, error information is recorded here when the value is not in any of the numeric formats recognized by Tcl.

const char *bytes (入力in)
  調べられる文字列値の第一バイトを指す｡ Points to first byte of the string value to be examined.

Tcl_Size numBytes (入力in)
  調べられるべき､ bytesから始まる､バイトの個数｡ もし､numBytesが負数の場合､調査を終了する､最初のNULLバイト迄､全てのバイトが調査される筈｡[訳註:NUL-->NULL] The number of bytes, starting at bytes, that should be examined. If numBytes is negative, then all bytes should be examined until the first NUL byte terminates examination.

void * *clientDataPtr (出力out)
  そこを通して､読み出す数的値を利用できる指示子の値を書いてもよい､空白を指す｡ Points to space where a pointer value may be written through which a numeric value is available to read.

int *typePtr (出力out)
  どの型の数的貯蔵が､読出して利用できるかの､値を書いてもよい､空白を指す｡ Points to space where a value may be written reporting what type of numeric storage is available to read.

Tcl_Obj *objPtr (入力in)
  調べられるべきTcl値｡ A Tcl value to be examined.

### 説明 DESCRIPTION

これ等の手続き函数は､Tclによって認識できる数的書式のTcl値から数的値を取出す事を可能にする｡ These procedures enable callers to retrieve a numeric value from a Tcl value in a numeric format recognized by Tcl.

Tclは多くの値を数として認識する｡幾つかの例は次を含む: "0", " +1", "-2 "," 3 ", "0xdad1", "0d09","1_000_000", "4.0", "1e-7", "NaN","Inf"｡ 組込みTcl命令がこれ等の値に数的として働いて､C言語内で効率的に扱える数的表現に変換する｡Tclはこれ等の表現を保存する為にC言語の三つの型を使う: double と Tcl_WideInt と mp_int｡ double型はC言語標準によって提供される｡ Tcl_WideInt型はTcl冒頭ファイルtcl.h内で宣言され､多くのOS上のC言語標準型long longと同じである｡mp_int型は冒頭ファイルtclTomMath.h内で宣言され､Tclに含まれているLibTomMath多重精度整数外部函数によって実装される｡[訳註:十進数前置辞0dはTcl8.6版迄は不都合になる｡tcl9.0版は可?] Tcl recognizes many values as numbers. Several examples include: "0", " +1", "-2 ", " 3 ", "0xdad1", "0d09", "1_000_000", "4.0", "1e-7", "NaN", or "Inf". When built-in Tcl commands act on these values as numbers, they are converted to a numeric representation for efficient handling in C code. Tcl makes use of three C types to store these representations: double, Tcl_WideInt, and mp_int. The double type is provided by the C language standard. The Tcl_WideInt type is declared in the Tcl header file, tcl.h, and is equivalent to the C standard type long long on most platforms. The mp_int type is declared in the header file tclTomMath.h, and implemented by the LibTomMath multiple-precision integer library, included with Tcl.

処理譜のTcl_GetNumberとTcl_GetNumberFromObjは同じ機能を遂行する｡ それらは､調べられる為にTcl値が如何に引数に与えられるか､のみが違う｡ Tcl_GetNumberは､引数bytes と numBytesに勘定された文字列を受容れる(又は､numBytesが負数の時は､ヌル終端文字列値)｡Tcl_GetNumberFromObjは､objPtr内のTcl値を受容れる｡ The routines Tcl_GetNumber and Tcl_GetNumberFromObj perform the same function. They differ only in how the arguments present the Tcl value to be examined. Tcl_GetNumber accepts a counted string value in the arguments bytes and numBytes (or a NUL-terminated string value when numBytes is negative). Tcl_GetNumberFromObj accepts the Tcl value in objPtr.

両法の処理譜はTclあ値を調べ､Tclが数としてそれを認識できるかを決定する｡ もし､否なら､両方の処理譜は TCL_ERROR を返し､且つ（interpがNULLでなければ）､interp内に､不都合伝言文と不都合番号を記録する｡ Both routines examine the Tcl value and determine whether Tcl recognizes it as a number. If not, both routines return TCL_ERROR and (when interp is not NULL) record an error message and error code in interp.

もし､Tclが調べている値を数であると認識すると､両方の処理譜は､TCL_OKを返し､且つ､指示子引数 clientDataPtr と typePtr(これはヌルではない) を使い､呼出側に数的表現を取出す為に使用できる情報を報告する｡ 両方の処理譜は *clientDataPtrに､Tclが変換された数的値を保持する内部貯蔵場所への指示子を､書く｡ If Tcl does recognize the examined value as a number, both routines return TCL_OK, and use the pointer arguments clientDataPtr and typePtr (which may not be NULL) to report information the caller can use to retrieve the numeric representation. Both routines write to *clientDataPtr a pointer to the internal storage location where Tcl holds the converted numeric value.

変換された数的値がdoubleとして保存された時､数学的外部函数isnanへの呼出しは､その値が数値ではない(NaN)か否かを定める｡もし､そうであれば､Tcl_GetNumberとTcl_GetNumberFromObjの両方は､値TCL_NUMBER_NANを*typePtrに書く｡もし､否なら､両方は､値TCL_NUMBER_DOUBLEを*typePtrに書く｡[訳註:この書き方は取扱い説明書の記述としては疑問]｡これ等記述譜は､この様な異なる型値を報告する､理由は､Tcl_GetDoubleFromObjはNaN値では不都合を発するから｡両方の報告された型値に関して､貯蔵指示子は型const double *が投げ込まれ､double数的値が読上げられるかもしれない｡ When the converted numeric value is stored as a double, a call to math library routine isnan determines whether that value is not a number (NaN). If so, both Tcl_GetNumber and Tcl_GetNumberFromObj write the value TCL_NUMBER_NAN to *typePtr. If not, both routines write the value TCL_NUMBER_DOUBLE to *typePtr. These routines report different type values in these cases because Tcl_GetDoubleFromObj raises an error on NaN values. For both reported type values, the storage pointer may be cast to type const double * and the double numeric value may be read through it.

変換された数的値がTcl_WideIntとして保存された時､Tcl_GetNumberとTcl_GetNumberFromObjの両方は､値TCL_NUMBER_INTを*typePtrに書く｡ 貯蔵指示子は､const Tcl_WideInt *が投げ込まれ､Tcl_WideInt 数的値が読上げられるかもしれない｡ When the converted numeric value is stored as a Tcl_WideInt, both Tcl_GetNumber and Tcl_GetNumberFromObj write the value TCL_NUMBER_INT to *typePtr. The storage pointer may be cast to type const Tcl_WideInt * and the Tcl_WideInt numeric value may be read through it.

変換された数的値がmp_intとして保存された時､Tcl_GetNumberとTcl_GetNumberFromObjの両方は､値TCL_NUMBER_BIGを*typePtrに書く｡ 貯蔵指示子は､const mp_int *が投げ込まれ､mp_int 数的値が読上げられるかもしれない｡ When the converted numeric value is stored as an mp_int, both Tcl_GetNumber and Tcl_GetNumberFromObj write the value TCL_NUMBER_BIG to *typePtr. The storage pointer may be cast to type const mp_int * and the mp_int numeric value may be read through it.

将来のTcl出版は､数としての値の認識を拡張か改訂するかもしれない｡ もし､追加の貯蔵表現が適用されると､これらの処理譜は､それを識別する為に､*typePtrに書かれる新しい値を加える｡ 呼出側は､*typePtrに書込む為の､未知の値に､それらがどの様に反応するかを考慮すべき｡ Future releases of Tcl might expand or revise the recognition of values as numbers. If additional storage representations are adopted, these routines will add new values to be written to *typePtr to identify them. Callers should consider how they should react to unknown values written to *typePtr.

これらの処理譜の呼出者が､報告された貯蔵指示子を通して数的値を読む時､ 彼らは､Tcl外部函数に属する記憶域を利用する｡ Tcl外部函数は､この記憶域を､上書きや破棄する能力がある｡ Tcl_GetNumberやTcl_GetNumberFromObjへの呼出しにより報告された貯蔵域指示子は､ 同じ時分割細片が､Tcl外部函数への制御を返すかもしれない､ 後には､使われてはならない｡ 数的値への利用が長い期間を要する場合､呼出側によって､ それが複写されるべきであろう｡呼出側は､貯蔵指示子への書込みや破棄を試みてはならない｡ 　 When callers of these routines read numeric values through the reported storage pointer, they are accessing memory that belongs to the Tcl library. The Tcl library has the power to overwrite or free this memory. The storage pointer reported by a call to Tcl_GetNumber or Tcl_GetNumberFromObj should not be used after the same thread has possibly returned control to the Tcl library. If longer term access to the numeric value is needed, it should be copied into memory controlled by the caller. Callers must not attempt to write through or free the storage pointer.

### SEE ALSO

Tcl_GetDouble, Tcl_GetDoubleFromObj, Tcl_GetWideIntFromObj

### KEYWORDS

double, double value, double type, integer, integer value, integer type, internal representation, value, value type, string representation