请问输出1.0/0.0的结果是inf是什么意思?
#include<stdio.h>
int main()
{
printf("%lf\n", 1.0 / 0.0);
return 0;
}
infinite
极大的,无法衡量的
仅供参考:
// https://docs.microsoft.com/en-us/cpp/c-runtime-library/format-specification-syntax-printf-and-wprintf-functions?view=vs-2019
// https://docs.microsoft.com/zh-cn/cpp/porting/visual-cpp-change-history-2003-2015?view=vs-2019
//
// Starting in Visual Studio 2015, if the argument that corresponds to a floating-point conversion specifier (a, A, e, E, f, F, g, G) is infinite,
// indefinite, or NaN, the formatted output conforms to the C99 standard. This table lists the formatted output:
// Value Output
// -------------- ---------
// infinity inf
// Quiet NaN nan
// Signaling NaN nan(snan)
// Indefinite NaN nan(ind)
// Any of these values may be prefixed by a sign. If a floating-point type conversion specifier character is a capital letter,
// then the output is also formatted in capital letters. For example, if the format specifier is %F instead of %f, an infinity
// is formatted as INF instead of inf. The scanf functions can also parse these strings, so these values can make a round trip
// through printf and scanf functions.
//
// Before Visual Studio 2015, the CRT used a different, non-standard format for output of infinite, indefinite, and NaN values:
// Value Output
// ------------------------------ -------------------------
// + infinity 1.#INF random-digits
// - infinity -1.#INF random-digits
// Indefinite (same as quiet NaN) digit .#IND random-digits
// NaN digit .#NAN random-digits
// Any of these may have been prefixed by a sign, and may have been formatted slightly differently depending on field width and precision,
// sometimes with unusual effects. For example, printf("%.2f\n", INFINITY) would print 1.#J because the #INF would be "rounded" to 2 digits of precision.
#include <stdio.h>
#include <float.h>
int main() {
int r;
double d1=-1.0,d2=-2.0;
printf("input two double (d1 d2):");
r=scanf("%lf%lf",&d1,&d2);
printf("scanf return:%d d1:%lg d2:%lg\n",r,d1,d2);
printf("_finite(d1):%d\n",_finite(d1));
printf("_fpclass(d1):0x%04X\n",_fpclass(d1));
return 0;
}
// input two double (d1 d2):nan 22
// scanf return:2 d1:nan d2:22
// _finite(d1):0
// _fpclass(d1):0x0002
//
// input two double (d1 d2):nan(snan) 22
// scanf return:2 d1:nan(snan) d2:22
// _finite(d1):0
// _fpclass(d1):0x0002
//
// input two double (d1 d2):nan(ind) 22
// scanf return:2 d1:-nan(ind) d2:22
// _finite(d1):0
// _fpclass(d1):0x0002
//
// input two double (d1 d2):-inf 22
// scanf return:2 d1:-inf d2:22
// _finite(d1):0
// _fpclass(d1):0x0004
0.0做分母