標準/拡張機能 | C/C++ | 依存項目 |
---|---|---|
C99 |
両方 | z/OS V1R7 |
#define _ISOC99_SOURCE
#include <math.h>
double nan(const char *tagp);
float nanf(const char *tagp);
long double nanl(const char *tagp);
関数 | Hex | IEEE |
---|---|---|
nan | X | X |
nanf | X | X |
nanl | X | X |
正常に実行された場合、tagp によって指示された内容の静止 NaN を戻します。
16 進の場合の特殊な動作: nan() ファミリーの関数は常に 0 を戻します。
/*
* This program illustrates the use of the nan() function
*
* It calls both nan and strtod with equivalent arguments
* and displays output of both. Output should be identical.
*
*/
#define _ISOC99_SOURCE
#include <stdio.h>
#include <stdlib.h> /* needed of strtod */
#include <math.h>
#define TESTVALS 5
struct {
const char * str;
} nan_vals[] = {
/*0*/ { "0" },
/*1*/ { "1" },
/*2*/ { "something" }, /* invalid n-char seq. */
/*3*/ { "2147483647" }, /* int max */
/*4*/ { "2147483648" } /* int max +1 */
},
strod_vals[] = {
/*0*/ { "NAN(0)" },
/*1*/ { "NAN(1)" },
/*2*/ { "NAN" },
/*3*/ { "NAN(2147483647)" },
/*4*/ { "NAN(2147483648)" }
};
void main()
{
double outnan,
outstrtod;
int i;
char *tagp = (char *)NULL;
printf("Illustrates the nan() function¥n");
printf("Output for both nan() and strtod() should be identical.¥n¥n");
for (i=0; i<TESTVALS; i++) {
outnan = nan(nan_vals[i].str);
outstrtod = strtod(strod_vals[i].str, &tagp);
printf("nan(%s) returned = %g¥n",nan_vals[i].str, outnan);
printf("strtod(%s) returned = %g¥n¥n",strod_vals[i].str, outstrtod);
}
}
出力:
Illustrates the nan() function
Output for both nan() and strtod() should be identical.
nan(0) returned = 0
strtod(NAN(0)) returned = 0
nan(1) returned = NaNQ(1)
strtod(NAN(1)) returned = NaNQ(1)
nan(something) returned = NaNQ(1)
strtod(NAN) returned = NaNQ(1)
nan(2147483647) returned = NaNQ(2147483647)
strtod(NAN(2147483647)) returned = NaNQ(2147483647)
nan(2147483648) returned = 0
strtod(NAN(2147483648)) returned = 0