nan

Is it a good idea to use IEEE754 floating point NaN for values which are not set?

笑着哭i 提交于 2019-11-29 09:23:14
Is it a good idea to use IEEE754 floating point NaN (not-a-number) for values which are undefined for non-mathematical reasons? In our case they are not yet set because the values have not been received from some other device. The context is an embedded system using IEC1131 REAL32 values. Edit: The programming language is C, so we would most likely use NAN and isnanf(x), which are from C99. Though we may need some extra contortions to get these into our OS compatibility layer. The default in programming languages seems to be to initialize floating point variables with positive zero, whose

Is null considered zero and undefined not a number on arithmetic expressions?

ε祈祈猫儿з 提交于 2019-11-29 09:17:06
Is null evaluated to 0 and undefined to NaN on arithmetic expressions? According to some testing it seems so: > null + null 0 > 4 + null 4 > undefined + undefined NaN > 4 + undefined NaN Is it safe or correct to assume this? (a quote from a documentation would be A+). Is null evaluated to 0 and undefined to NaN on arithmetic expressions? Is it safe or correct to assume this? Yes, it is. An "arithmetic expression" would use the ToNumber operation : Argument Type | Result --------------+-------- Undefined | NaN Null | +0 … | It is used in the following "arithmetic" expressions: prefix / postfix

Confusion on NaN in Java

心不动则不痛 提交于 2019-11-29 06:44:35
问题 int i = 0, j = 0; double nan1 = (double)0/0; double nan2 = (double)0/0; double nan3 = (double)i/j; System.out.println(Double.doubleToRawLongBits(nan1) == Double.doubleToRawLongBits(nan2)); System.out.println(Double.doubleToRawLongBits(nan1) == Double.doubleToRawLongBits((double)0/0)); System.out.println(Double.doubleToRawLongBits(nan3) == Double.doubleToRawLongBits(nan2)); output: true true false Please help me how the output came true for first two and false for last one. Please tell me what

How are Inf and NaN implemented?

跟風遠走 提交于 2019-11-29 06:32:47
As mathematical concepts, I am well aware of what inf and nan actually are. But what I am really interested in is how they are implemented in programming languages. In python, I can use inf and nan in arithmetic and conditional expressions, like this: >>> nan = float('nan') >>> inf = float('inf') >>> 1 + inf inf >>> inf + inf inf >>> inf - inf nan This would lead me to believe that python internally has a special reserved bit sequence for these two mathematical quantities, and no other number can assume these positions. Is my assumption correct? Can you please enlighten me in this regard? If

what does NaN mean for doubles?

给你一囗甜甜゛ 提交于 2019-11-29 05:29:36
What's the difference between NaN and Infinity ? When does NaN appear? What is it? From Wikipedia : In computing, NaN (Not a Number) is a value of the numeric data type representing an undefined or unrepresentable value, especially in floating-point calculations. Systematic use of NaNs was introduced by the IEEE 754 floating-point standard in 1985, along with the representation of other non-finite quantities like infinities. And from MSDN : Represents a value that is not a number (NaN). This field is constant. The value of this constant is the result of dividing zero by zero. This constant is

How do you check for infinite and indeterminate values in C++?

↘锁芯ラ 提交于 2019-11-29 05:05:36
问题 In my programs infinity usually arises when a value is divided by zero. I get indeterminate when I divide zero by zero. How do you check for infinite and indeterminate values in C++? In C++, infinity is represented by 1.#INF. Indeterminate is represented by -1.#IND. The problem is how to test if a variable is infinite or indeterminate. Checking infinity is relatively straightforward: You find the infinity definition in your particular C++. For my case (VS2003), it is std::numeric_limits:

NaN Literal in C?

假装没事ソ 提交于 2019-11-29 03:14:10
How do you write an NaN floating-point literal in C? In C99's <math.h> 7.12 Mathematics <math.h> [#5] The macro NAN is defined if and only if the implementation supports quiet NaNs for the float type. It expands to a constant expression of type float representing a quiet NaN. | 5.2.4.2.2/3: floating types may be able to contain other kinds of floating-point numbers, such as ... infinities and NaNs. A NaN is an encoding signifying Not-a-Number. A quiet NaN propagates through almost every arithmetic operation without raising a floating-point exception; a signaling NaN generally raises a floating

Why does Release/Debug have a different result for std::min?

最后都变了- 提交于 2019-11-29 02:48:37
Here is the test program: void testFunc() { double maxValue = DBL_MAX; double slope = std::numeric_limits<double>::quiet_NaN(); std::cout << "slope is " << slope << std::endl; std::cout << "maxThreshold is " << maxValue << std::endl; std::cout << "the_min is " << std::min( slope, maxValue) << std::endl; std::cout << "the_min is " << std::min( DBL_MAX, std::numeric_limits<double>::quiet_NaN()) << std::endl; } int main( int argc, char* argv[] ) { testFunc(); return 0; } In Debug, I get: slope is nan maxThreshold is 1.79769e+308 the_min is nan the_min is 1.79769e+308 In Release, I get: slope is

Python : NaN value in Pandas for a single value only

[亡魂溺海] 提交于 2019-11-29 01:40:23
问题 I just want to check if a single cell in Pandas series is null or not. i.e, I'd like to check if a value is NaN . All other answers are for series and arrays, but not for single value. I have tried pandas.notnull , pandas.isnull , numpy.isnan . Is there a solution for a single value only? 回答1: Try this: import pandas as pd import numpy as np from pandas import * >>> L = [4, nan ,6] >>> df = Series(L) >>> df 0 4 1 NaN 2 6 >>> if(pd.isnull(df[1])): print "Found" Found >>> if(np.isnan(df[1])):

Comparing NumPy arrays so that NaNs compare equal

房东的猫 提交于 2019-11-29 01:15:01
Is there an idiomatic way to compare two NumPy arrays that would treat NaNs as being equal to each other (but not equal to anything other than a NaN). For example, I want the following two arrays to compare equal: np.array([1.0, np.NAN, 2.0]) np.array([1.0, np.NAN, 2.0]) and the following two arrays to compare unequal: np.array([1.0, np.NAN, 2.0]) np.array([1.0, 0.0, 2.0]) I am looking for a method that would produce a scalar Boolean outcome. The following would do it: np.all((a == b) | (np.isnan(a) & np.isnan(b))) but it's clunky and creates all those intermediate arrays. Is there a way that