使用这个函数进行判断
帮助信息内的描述如下
_chkfloat_
#include <intrins.h>
unsigned char _chkfloat_ (float val); /* number for error checking */
Description:
The _chkfloat_ function checks the status of a floating-point number.
Return Value:
The _chkfloat_ function returns an unsigned char that contains the following status information:
Attributes:
reentrant, intrinsic
Example
#include <intrins.h>
#include <stdio.h> /* for printf */
char _chkfloat_ (float);
float f1, f2, f3;
void tst_chkfloat (void) {
f1 = f2 * f3;
switch (_chkfloat_ (f1)) {
case 0:
printf ("result is a number\n"); break;
case 1:
printf ("result is zero\n"); break;
case 2:
printf ("result is +INF\n"); break;
case 3:
printf ("result is -INF\n"); break;
case 4:
printf ("result is NaN\n"); break;
}
}
参考链接
单片机keil_C51如何返回NaN - 24小时必答区 (51hei.com)http://www.51hei.com/bbs/dpj-225267-1.html
特此记录
anlog
2024年9月23日