Profile

ys2310

Author:ys2310
2008年春にNew York Cityにあるふる〜い大学を卒業。


Categories


new postings


new comments


new trackbacks


monthly archeive


FC2ブログ 転職
DATE: CATEGORY:スポンサー広告
上記の広告は1ヶ月以上更新のないブログに表示されています。
新しい記事を書く事で広告が消せます。
| BLOG TOP |
DATE: CATEGORY:C/C++ macro

9.5. Limits

Two header files <float.h> and <limits.h> define several implementation specific limits.

9.5.1. Limits.h

Table 9.1 gives the names declared, the allowable values, and a comment on what they mean. For example, the description of SHRT_MIN shows that in a given implementation the value must be less than or equal to −32767: this means that for maximum portability a program cannot rely on short variables being able to hold values more negative than −32767. Implementations may choose to support values which are more negative but must provide support for at least −32767.

NameAllowable valueComment
CHAR_BIT (≥8) bits in a char
CHAR_MAX see note max value of a char
CHAR_MIN see note min value of a char
INT_MAX (≥+32767) max value of an int
INT_MIN (≤−32767) min value of an int
LONG_MAX (≥+2147483647) max value of a long
LONG_MIN (≤−2147483647) min value of a long
MB_LEN_MAX (≥1) max number of bytes in a multibyte character
SCHAR_MAX (≥+127) max value of a signed char
SCHAR_MIN (≤−127) min value of a signed char
SHRT_MAX (≥+32767) max value of a short
SHRT_MIN (≤−32767) min value of a short
UCHAR MAX (≥255U) max value of an unsigned char
UINT_MAX (≥65535U) max value of an unsigned int
ULONG_MAX (≥4294967295U) max value of an unsigned long
USHRT_MAX (≥65535U) max value of an unsigned short
Note: if the implementation treats chars as signed, then the values of CHAR_MAX and CHAR_MIN are the same as the equivalent SCHAR versions. If not, then the value of CHAR_MIN is zero and the value of CHAR_MAX is equal to the value of UCHAR_MAX.
Table 9.1. <limits.h>

9.5.2. Float.h

For floating point numbers, the file <float.h> contains a similar set of minimum values. (It is assumed that where no minimum value is specified, there is either no minimum, or the value depends on another value.)

Name Allowable value Comment
FLT_RADIX (≥2) the radix of exponent representation
DBL_DIG (≥10) the number of digits of precision in a double
DBL_EPSILON (≤1E−9) minimum positive number such that 1.0 + x ≠ 1.0
DBL_MANT_DIG (—) the number of base FLT_RADIX digits in the mantissa part of a double
DBL_MAX (≥1E+37) max value of a double
DBL_MAX_10_EXP (≥+37) max value of exponent (base 10) of a double
DBL_MAX_EXP (—) max value of exponent (base FLT_RADIX)) of a double
DBL_MIN (≤1E−37) min value of a double
DBL_MIN_10_EXP (≤37) minimum value of exponent (base 10) of a double
DBL_MIN_EXP (—) min value of exponent part of a double (base FLT_RADIX)
FLT_DIG (≥6) the number of digits of precision in a float
FLT_EPSILON (≤1E−5) minimum positive number such that 1.0 + x ≠ 1.0
FLT_MANT_DIG (—) the number of base FLT_RADIX digits in the mantissa of a float
FLT_MAX (≥1E+37) max value of a float
FLT_MAX_10_EXP (≥+37) max value (base 10) of exponent part of a float
FLT_MAX_EXP (—) max value (base FLT_RADIX) of exponent part of a float
FLT_MIN (≤1E−37) min value of a float
FLT_MIN_10_EXP (≤−37) min value (base 10) of exponent part of a float
FLT_MIN_EXP (—) min value (base FLT_RADIX) of exponent part of a float
FLT_ROUNDS (0)

affects rounding of floating point addition:

−1
indeterminate
0
towards zero
1
to nearest
2
towards +infinity
3
towards -infinity

any other value is implementation defined.

LDBL_DIG (≥10) the number of digits of precision in a long double
LDBL_EPSILON (≤1E−9) minimum positive number such that 1.0 + x ≠= 1.0
LDBL_MANT_DIG (—) the number of base FLT_RADIX digits in the mantissa part of a long double
LDBL_MAX (≥1E+37) max value of a long double
LDBL_MAX_10_EXP (≥+37) max value of exponent (base 10) of a long double
LDBL_MAX_EXP (—) max value of exponent (base FLT_RADIX) of a long double
LDBL_MIN (≤1E−37) minimum value of a long double
LDBL_MIN_10_EXP (≤−37) min value of exponent part (base 10) of a long double
LDBL_MIN_EXP (—) min value of exponent part of a long double (base FLT_RADIX)
Table 9.2. <float.h>



[Quote]:http://publications.gbdirect.co.uk/c_book/chapter9/limits.html

| BLOG TOP |
DATE: CATEGORY:C/C++ macro
Mathematical functions

If you are writing mathematical programs, involving floating point calculations and so on, then you will undoubtedly require access to the mathematics library. This set of functions all take double arguments, and return a double result. The functions and associated macros are defined in the include file .

The macro HUGE_VAL is defined, which expands to a positive double expression, which is not necessarily representable as a float.

For all the functions, a domain error occurs if an input argument is outside the domain over which the function is defined. An example might be attempting to take the square root of a negative number. If this occurs, errno is set to the constant EDOM, and the function returns an implementation defined value.

If the result of the function cannot be represented as a double value then a range error occurs. If the magnitude of the result is too large, the functions return ±HUGE_VAL (the sign will be correct) and errno is set to ERANGE. If the result is too small, 0.0 is returned and the value of errno is implementation defined.

The following list briefly describes each of the functions available:

double acos(double x);
Principal value of the arc cosine of x in the range 0–π radians.
Errors: EDOM if x is not in the range −1–1.
double asin(double x);
Principal value of the arc sine of x in the range -π/2–+π/2 radians.
Errors: EDOM if x is not in the range −1–1.
double atan(double x);
Principal value of the arc tangent of x in the range -π/2–+π/2 radians.
double atan2(double y, double x);
Principal value of the arc tangent of y/x in the range -π–+π radians, using the signs of both arguments to determine the quadrant of the return value.
Errors: EDOM may occur if both x and y are zero.
double cos(double x);
Cosine of x (x measured in radians).
double sin(double x);
Sine of x (x measured in radians).
double tan(double x);
Tangent of x (x measured in radians). When a range error occurs, the sign of the resulting HUGE_VAL is not guaranteed to be correct.
double cosh(double x);
Hyperbolic cosine of x.
Errors: ERANGE occurs if the magnitude of x is too large.
double sinh(double x);
Hyperbolic sine of x.
Errors: ERANGE occurs if the magnitude of x is too large.
double tanh(double x);
Hyperbolic tangent of x.
double exp(double x);
Exponential function of x. Errors: ERANGE occurs if the magnitude of x is too large.
double frexp(double value, int *exp);
Break a floating point number into a normalized fraction and an integral power of two. This integer is stored in the object pointed to by exp.
double ldexp(double x, int exp);
Multiply x by 2 to the power exp
Errors: ERANGE may occur.
double log(double x);
Natural logarithm of x.
Errors: EDOM occurs if x is negative. ERANGE may occur if x is zero.
double log10(double x);
Base-ten logarithm of x.
Errors: EDOM occurs if x is negative. ERANGE may occur if x is zero.
double modf(double value, double *iptr);
Break the argument value into integral and fractional parts, each of which has the same sign as the argument. It stores the integrbal part as a double in the object pointed to by iptr, and returns the fractional part.
double pow(double x, double y);
Compute x to the power y.
Errors: EDOM occurs if x < 0 and y not integral, or if the result cannot be represented if x is 0, and y ≤ 0. ERANGE may also occur.
double sqrt(double x);
Compute the square root of x.
Errors: EDOM occurs if x is negative.
double ceil(double x);
Smallest integer not less than x.
double fabs(double x);
Absolute value of x.
double floor(double x);
Largest integer not greater than x.
double fmod(double x, double y);
Floating point remainder of x/y.
Errors: If y is zero, it is implementation defined whether fmod returns zero or a domain error occurs.

[Quote]:http://64.233.167.104/search?q=cache:Q1DXRLum_skJ:publications.gbdirect.co.uk/c_book/chapter9/maths_functions.html+C+ERANGE&hl=en&ct=clnk&cd=8&gl=us&lr=lang_en|lang_ja&client=firefox-a

| BLOG TOP |
DATE: CATEGORY:C/C++ macro

構文

#include <limits.h>

説明

次の記号は、 <limits.h> で定義されています。 これらは、このマニュアルの説明文中で使用されているものです。 HP-UX 値 欄は、すべての HP-UX システムで移植性のあるアプリケーションを 作成するために想定すべき値を示しています。

値の後の記号は、次に示す意味を持っています。

+  

いくつかの HP-UX システムでは、ここで示される値よりも実際の限界値が大きいことがあります。

-  

いくつかの HP-UX システムでは、ここで示される値よりも実際の限界値が小さいことがあります。

=  

実際の限界値は、ここで示される値と常に等しく、すべての HP-UX システムで同じです。

*  

この限界値の名前が定義されるのは、 コンパイル時に -D_XPG2 フラグを指定するか、ソースプログラムで <limits.h> がインクルードされる前に #define 指令のどちらか一方を用いることによって、 プリプロセッサマクロ _XPG2 が定義されているとき だけ です。

#  

この限界値の定義値は、コンパイル時定数でないことがあります。 常にこの定義値は、実行時に整数式として計算されます。

これらの限界値の中には、システム構成によって違うものがあります。 その値は、 sysconf(2) を使って動的にに知ることができます。 また、ファイルシステムや、特殊ファイルに対応するデバイスに よって違うものがあります。 その値は pathconf(2) を使って知ることができます。 さらに、時代遅れのものもあります。 他の限界値に対して冗長であったり、移植可能なアプリケーションを 作成するのに役立ちません。 これらは、他のシステムからのアプリケーションの移植や、『 X/Open Portability Guide, Issue 2 』に従うアプリケーションをサポートしたり、以前の HP-UX の旧製品との互換性を保つために提供されています。 新しいアプリケーションでは _XPG2 フラグを定義しないでください。

コンパイルの際に <limits.h> ファイルをインクルードして、 そのアプリケーションが、ある特定のシステムで動作できるかどうかを 調べるための適当な限界値を検査することができます。 さらに、そのシステムに適合するようにアプリケーションの挙動を変えて、 様々な範囲にわたる限界値の設定やシステムの移植性を向上することもできます。

\".na

定数説明HP-UX 値ARG_MAX
環境データを含む、 exec(2)への引き数の最大長 (バイト単位)5120 +*  
CHAR_BITchar のビット数8 = 
CHAR_MAXchar の最大整数値127 = 
CHAR_MINchar の最小整数値-128 = 
CHILD_MAXユーザー ID あたりの並行プロセス の最大個数25 +-* 
CLK_TCK1 秒間あたりのクロックチック数50 +# 
DBL_DIGdouble の精度の桁数15 + 
DBL_MAXdouble の最大正数値1.7976931348623157e+308 + 
DBL_MINdouble の最小正数値4.94065645841246544e-324 - 
FCHR_MAXファイルの最大オフセット (バイト単位)INT_MAX +-* 
FLT_DIGfloat の精度の桁数6 + 
FLT_MAXfloat の最大正数値3.40282346638528860e+38 + 
FLT_MINfloat の最小正数値1.40129846432481707e-45 - 
INT_MAXint の最大 10 進値2147483647 + 
INT_MINint の最小 10 進値-2147483648 - 
LINE_MAX1 行あたりの最大文字数2048 = 
LINK_MAX1 ファイルあたりの最大リンク数32767 +* 
LOCK_MAXシステムロック テーブルの最大エントリー数32 +-* 
LONG_BITlong のビット数32 + 
LONG_MAXlong の最大 10 進値2147483647 + 
LONG_MINlong の最小 10 進値-2147483648 - 
MAX_CANONターミナル基準入力行に含まれる最大バイト数512 +* 
MAX_CHARターミナル入力キューに含まれる最大バイト数MAX_INPUT =* 
MAX_INPUTターミナル入力キューに含まれる最大バイト数512 +* 
NAME_MAX1 つのパス名構成要素の最大バイト数14 +* 
NL_ARGMAXNLS printf(3S) 関数および scanf(3S)関数の呼出しの際の最大「桁」数9 = 
NL_MSGMAX1 つの NLS メッセージカタログに含まれる 最大メッセージ数32767 + 
NL_SETMAX1 つの NLS メッセージカタログに含まれる 最大セット数255 + 
NL_TEXTMAX1 つの NLS メッセージ文字列に含まれる 最大バイト数8192 + 
NGROUPS_MAXプロセスあたりの最大補助グループ数20 + 
OPEN_MAX1 つのプロセスがオープンできる最大ファイル数60 +* 
PASS_MAX1 つのパスワードに含まれる最大文字数8 + 
PATH_MAXnull ターミネータを除く、 1 つのパス名に含まれる最大文字数1023 +* 
PID_MAX1 つのプロセス ID の最大値30000 + 
PIPE_BUF1 つのパイプへの書込み単位の最大バイト数8192 +* 
PIPE_MAX1 回の書込みで 1 つのパイプに書き込める最大バイト数INT_MAX + 
PROC_MAXシステムの最大並行プロセス数84 +-* 
SCHAR_MAXsigned char の最大整数値127 = 
SCHAR_MINsigned char の最小整数値-128 = 
SHRT_MAXshort の最大 10 進値32767 + 
SHRT_MINshort の最小 10 進値-32768 - 
STD_BLK物理的 I/O ブロックに含まれるバイト数512 + 
SYSPID_MAXシステムプロセスの最大プロセス ID4 +-* 
SYS_NMLNuname(2) が返す文字列の長さ8 +* 
SYS_OPENシステムでオープンされるファイルの最大個数120 +-* 
TMP_MAXtmpnam(3S) が生成するユニークな名前の 最大個数17576 + 
UCHAR_MAXunsigned char の最大整数値255 = 
UID_MAXユーザー ID やグループ ID として 使用できない値の最小値2147483647 + 
UINT_MAXunsigned int の最大 10 進値4294967295 + 
ULONG_MAXunsigned long の最大 10 進値4294967295 + 
USHRT_MAXunsigned short の最大 10 進値65535 + 
USI_MAXunsigned int の最大 10 進値UINT_MAX =* 
WORD_BIT1 つの「ワード」 (int) 中のビット数32 + 


[Quote]:http://64.233.167.104/search?q=cache:CV3oOiXYuGAJ:www.docs.hp.com/ja/B2355-60104-09/limits.5.html+INT_MAX&hl=en&ct=clnk&cd=2&gl=us&lr=lang_en|lang_ja&client=firefox-a

| BLOG TOP |
DATE: CATEGORY:C/C++ macro
C++ offers new capabilities, some of which supplant those offered by the ANSI C preprocessor. These new capabilities enhance the type safety and predictability of the language:

* In C++, objects declared as const can be used in constant expressions. This allows programs to declare constants that have type and value information, and enumerations that can be viewed symbolically with the debugger. Using the preprocessor #define directive to define constants is not as precise. No storage is allocated for a const object unless an expression that takes its address is found in the program.

* The C++ inline function capability supplants function-type macros. The advantages of using inline functions over macros are:

o Type safety. Inline functions are subject to the same type checking as normal functions. Macros are not type safe.
o Correct handling of arguments that have side effects. Inline functions evaluate the expressions supplied as arguments prior to entering the function body. Therefore, there is no chance that an expression with side effects will be unsafe.

For more information on inline functions, see inline, __inline, __forceinline.

[Quote]:http://msdn2.microsoft.com/en-us/library/ttsbh614.aspx

| BLOG TOP |
DATE: CATEGORY:C/C++ macro
Preprocessing expands macros in all lines that are not preprocessor directives (lines that do not have a # as the first non-white-space character) and in parts of some directives that are not skipped as part of a conditional compilation. "Conditional compilation" directives allow you to suppress compilation of parts of a source file by testing a constant expression or identifier to determine which text blocks are passed on to the compiler and which text blocks are removed from the source file during preprocessing.

The #define directive is typically used to associate meaningful identifiers with constants, keywords, and commonly used statements or expressions. Identifiers that represent constants are sometimes called "symbolic constants" or "manifest constants." Identifiers that represent statements or expressions are called "macros." In this preprocessor documentation, only the term "macro" is used.

When the name of the macro is recognized in the program source text or in the arguments of certain other preprocessor commands, it is treated as a call to that macro. The macro name is replaced by a copy of the macro body. If the macro accepts arguments, the actual arguments following the macro name are substituted for formal parameters in the macro body. The process of replacing a macro call with the processed copy of the body is called "expansion" of the macro call.

In practical terms, there are two types of macros. "Object-like" macros take no arguments, whereas "function-like" macros can be defined to accept arguments so that they look and act like function calls. Because macros do not generate actual function calls, you can sometimes make programs run faster by replacing function calls with macros. (In C++, inline functions are often a preferred method.) However, macros can create problems if you do not define and use them with care. You may have to use parentheses in macro definitions with arguments to preserve the proper precedence in an expression. Also, macros may not correctly handle expressions with side effects. See the getrandom example in The #define Directive for more information.

Once you have defined a macro, you cannot redefine it to a different value without first removing the original definition. However, you can redefine the macro with exactly the same definition. Thus, the same definition can appear more than once in a program.

[Quote]:http://msdn2.microsoft.com/en-us/library/503x3e3s.aspx

| BLOG TOP |

copyright © Manhattan life all rights reserved.Powered by FC2ブログ