#QNAN、1.#IND和1.#INF等“无效”浮点数说明及其判断

news/2024/5/18 22:29:07 标签: variables, exception, signal, 语言, 数据库, sql

在GIS视图上发现部分小区不能正常呈现,通过跟踪异常小区发现其所属基站的经纬度坐标都是-1.#QNAN00000000000无效值,导致小区绘制失败,这些小区均属新入网的3G基站,资源数据还没有维护起来,数据库中对应字段为空,经过TUXEDO接口后数据反映为QNAN无效值。在基础数据完善之前,可在SQL取数据时将空值转化为0,或在接收数据时对此类数据作进一步的过滤。
  此处的1.#QNAN是一个打印呈现,QNAN是指Quiet Not a Number,类似的浮点错误还有SNaN(Signaling Not a Number),通常如0.0/0.0、给负数开平方根等溢出或无效运算就会产生一个NAN结果的表示值,NaN及两种浮点错误的说明如下:
The value NaN (Not a Number) is used to represent a value that does not represent a real number. NaN’s are represented by a bit pattern with an exponent of all 1s and a non-zero fraction. There are two categories of NaN: QNaN (Quiet NaN) and SNaN (Signalling NaN).
A QNaN is a NaN with the most significant fraction bit set. QNaN’s propagate freely through most arithmetic operations. These values pop out of an operation when the result is not mathematically defined.
An SNaN is a NaN with the most significant fraction bit clear. It is used to signal an exception when used in operations. SNaN’s can be handy to assign to uninitialized variables to trap premature usage.
Semantically, QNaN’s denote indeterminate operations, while SNaN’s denote invalid operations. If a return value is a QNaN, it means that it is impossible to determine the result of the operation, a SNaN means that the operation is invalid.
  这样的特殊浮点数还有INF和IND:INF就是Infinity,表示一个无穷大的数,包括正无穷和负无穷;IND则表示无限小,但不确定。如1.0/0.0会产生一个INF无穷大,-1.0/0.0会产生一个负无穷大。
 
  回到最初的错误上,这种无效数据之所以通过了经纬度有效值判断,是因为常规的浮点范围对这类浮点数无效。我们知道常规的浮点数不能直接判0等于,而如果这个浮点数为NaN,那if (f==f) 会得到false结果。但是利用这个结果来判断一个浮点数是否为NaN并不总是安全的,例如用这个宏定义#define isnan(x) ((x) != (x)) ,在某些编译环境下可能就会脱离了你的预期。那如何判断特殊的浮点数呢?各种语言应该都能找到对应的辅助函数或者类方法,在C语言中,可以用float.h中的int _isnan(double x)、int _finite(double x)、int _fpclass(double x)函数来判断,返回结果代表意义分别为:_FPCLASS_SNAN (Signaling NaN)、_FPCLASS_QNAN (Quiet NaN)、_FPCLASS_NINF (Negative Infinity, –INF)、_FPCLASS_PINF (Positive Infinity, +INF);在C++中,可以用STL中的limits类:numeric_limits::quiet_NaN()、numeric_limits::signaling_NaN()、numeric_limits::infinity()等方法。
 
更多信息可参考下面的文章:
http://www.ibm.com/developerworks/cn/java/j-jtp0114/
http://steve.hollasch.net/cgindex/coding/ieeefloat.html
http://www.topcoder.com/tc?module=Static&d1=tutorials&d2=integersReals2


http://www.niftyadmin.cn/n/1629471.html

相关文章

细说KVO

1.手动控制kvo的触发 (BOOL)automaticallyNotifiesObserversForKey:(NSString *)key; 返回NO ;然后在改变value前 调用[object willChangeValueForKey:"key"]; 在改变value后, 调用[object didChangeValueForKey:"key"] ;2.隔层kvo观察 interface Dog : NS…

UITableView 列表视图1

2019独角兽企业重金招聘Python工程师标准>>> /// 别忘了写 代理 <UITableViewDelegate,UITableViewDataSource>_tableView [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 416) style:UITableViewStylePlain];//Grouped 分组样式_tableView.del…

getResource()的使用总结 ;

1.通过ClassLoader来加载getResource&#xff08;&#xff09;时不需要加 "/" 因为source是从main开始的; Thread.currentThread().getContextClassLoader().getResource("main/test/test.txt").getPath(); 2.通过Class.getResource()来加载文件时需要加“…

GIT和SVN之间的五个基本区别

果你在读这篇文章&#xff0c;说明你跟大多数开发者一样对 GIT感兴趣&#xff0c;如果你还没有机会来试一试GIT&#xff0c;我想现在你就要了解它了。 GIT不仅仅是个版本控制系统&#xff0c;它也是个内容管理系统(CMS),工作管理系统等。如果你是一个具有使用SVN背景的人&#…

oracle 视图views

SELECT * FROM DBA_VIEWS WHERE VIEW_NAME你的视图名; SELECT * FROM USER_VIEWS WHERE VIEW_NAME你的视图名; SELECT * FROM ALL_VIEWS WHERE VIEW_NAME你的视图名; 转载于:https://www.cnblogs.com/520future/p/8442660.html

反转链表 | 单链表的逆置

面试题16&#xff1a;反转链表 一.题目描述 定义一个函数&#xff0c;输入一个链表的头结点&#xff0c;反转该链表并输出反转后链表的头结点。 链表结点定义如下&#xff1a; struct ListNode {int m_nKey;ListNode* m_pNext; }; 二.分析问题 1.举例分析 2.解题思路 解…

QToolBar 多行显示问题的解决方案

效果图如下&#xff1a;哈哈今天早上来突然找到解决方案了&#xff0c;希望对大家有用&#xff01;赶紧送上示例代码&#xff1a;void addToolBars() {QToolBar * barTest addToolBar(tr("test1"));..../// > barTest1的actions barTest->setMovable(false);t…

使用photoshop快速制作一、二寸寸照

你还在为没有吋照烦恼吗&#xff1f;还在为照相馆昂贵的寸照费烦恼吗&#xff1f;教你一招轻松快速制作大量的一、二寸吋照&#xff0c;只需到打印室直接打印即可以。一寸吋照尺寸&#xff1a;2.5cm*3.5cm小两寸照尺寸&#xff1a;3.3cm*4.8cm大两寸照尺寸&#xff1a;3.4cm*5.…