51单片机如何判断浮点数nan

使用这个函数进行判断

 帮助信息内的描述如下

_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)icon-default.png?t=O83Ahttp://www.51hei.com/bbs/dpj-225267-1.html

特此记录

anlog

2024年9月23日 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值