-1

Since 0.0 / 0.0 is mathematically undefined, the IEEE-754 floating-point standards reasonably define NaN as its result. Now, because unlike infinity, NaN is not a well-defined value, but a set of values, the question that whether 0.0 / 0.0 is a well defined constant or not is also reasonable.

It's worth it to mention that x / 0.0 would be infinity in IEEE-754 if x != 0.0.

Is 0.0 / 0.0 a well-defined constant NaN value in the IEEE-754 floating-point standards or not? In other words does it have a well-defined bit pattern or not?

plasmacel
  • 8,183
  • 7
  • 53
  • 101
  • Just to be pedantic: x/0.0 is mathematically *undefined* for all *x*: there is nothing indeterminate about it (division in only defined when the divisor is non zero). – Richard Jan 04 '18 at 09:35
  • @Richard Incorrect. `x / 0.0` is `infinity` if `x != infinity` and `x != 0`. – plasmacel Jan 04 '18 at 09:36
  • No it isn't (unless you use specific extensions to the reals for specific fields): check the axiomatic definition of the field of real numbers. – Richard Jan 04 '18 at 09:37
  • @Richard My bad, I interpreted your comment as IEEE-754 math. On the other hand indeterminate and undefined is just different wordings for the same thing. Wolfram Mathematica uses the word indeterminate for example. – plasmacel Jan 04 '18 at 09:39
  • @n.m. It's not end of story at all. If you manipulate floating-point numbers by assembly or by Intel ISA extensions (like SSE, AVX), then you are not limited by the type system, you can easily interpret a floating-point value as a bitfield (and you have to in some cases, i.e. the floating-point absolute value is an AND actually) so it can definitely matter. – plasmacel Jan 04 '18 at 09:45
  • x / 0.0 would be infinity even if x is infinity. – Pascal Cuoq Jan 04 '18 at 10:19
  • @PascalCuoq You are right, corrected. – plasmacel Jan 04 '18 at 10:21
  • Why do you want to know a specific encoding of the NaN in this case? (On re-reading this seems it could be an [XY Problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem).) Any platform with IEEE-754 support will need to have an `IsNaN` function to determine if a value is a NaN: why can't you use that? – Richard Jan 04 '18 at 11:02
  • @Richard Because not is that what I want to know. – plasmacel Jan 04 '18 at 11:03
  • Sorry, that last comment does not parse. – Richard Jan 04 '18 at 11:11
  • 2
    @Richard: To be properly pedantic, mathematicians use many different systems of numbers/arithmetic/symbols/logic. There is no absolute sense in which *x*/0.0 is or is not defined; whether it is defined for non-zero depends on which system you are using. These systems have various reasons for being useful, not the least because they model aspects of apparent reality very well, but none of them is perfect, and none of them has an absolute claim on truth. A pedantic claim about *x*/0 not being defined when the question clearly asks about IEEE 754 arithmetic, which does define it, is not helpful. – Eric Postpischil Jan 04 '18 at 13:07
  • @EricPostpischil 1. my second comment referenced that which is why I also said "field of reals" (which is not subject to variations around "extended number line"). 2. please re-read the start of the question. – Richard Jan 04 '18 at 13:15
  • @EricPostpischil While I completely agree with you, if we should be extremely pedantic (what we shouldn't) it's worth mentioning that actually `x/0` is defined as complex infinity, which is undefined on the set of real numbers. :] – plasmacel Jan 04 '18 at 13:16
  • @Richard: Not helping. – Eric Postpischil Jan 04 '18 at 14:19

2 Answers2

5

IEEE 754-2008 describes four levels for specifying floating-point data.

Level 1 is the extended real numbers—the real numbers plus −∞ and +∞. This is the level for regular mathematics; two divided by three is exactly two-thirds.

Level 2 is floating-point data. It includes all the values representable in floating-point (finite and infinite) plus a NaN, and it distinguishes −0 and +0. This is the level for floating-point arithmetic; operations return a value that is the exact mathematical value rounded to a representable value. Two divided by three in the basic 64-bit binary format using round-to-nearest mode is exactly 0.66666666666666662965923251249478198587894439697265625. This level is algebraically closed; any arithmetic operation on floating-point data produces floating-point data (possibly NaN).

Level 3 is representations of floating-point data. At this level, finite numbers are represented with a sign, an exponent, and a significand, and it includes −∞ and +∞ and two NaNs, a quiet (non-signaling) NaN and a signaling NaN. (A signaling NaN causes exceptions when used.) A significand is a fraction portion of the representation. If a binary floating-point number has an exponent of e and a significand of f, it represents a value of −f • 2e or +f • 2e, depending on its sign. At this level, that result of dividing two by three is a + sign, an exponent of -1, and a significand of 1.3333333333333332593184650249895639717578887939453125 or, in hexadecimal, 1.555555555555516.

Level 4 is bit strings. At this level:

  • For finite numbers, the sign is 0 (for +) or 1 (for −). For normal numbers, the exponent is encoded as an unsigned value by adding a bias to the actual exponent. For the basic 64-bit binary format, the bias is 1023, so an actual exponent of −1 is encoded as −1+1023 = 1022. The significand is encoded with its first bit removed. So, for 53-bit significands, only 52 bits are stored in the significand field. For subnormal numbers, the exponent is encoded as 0.

  • Infinity is encoded with a sign bit, an exponent field that is all ones (2047 in the basic 64-bit binary format), and a significand field that is all zeros.

  • NaNs are encoded with a sign bit, an exponent field that is all ones, and a significand field that is not all zeros. IEEE 754-2008 recommends that quiet NaNs be encoded with a 1 in the first bit of the significand field and signaling NaNs be encoded with a 0 in the first bit, but this is not required.

Since a “NaN” is not a number, IEEE 754-2008 avoids calling it a number or a value. A thing in level 2 is a datum.

NaNs are well defined data. Operations that produce them and operations on them are specified.

Technically, 0.0 / 0.0 is not a constant value; it is an expression. IEEE 754-2008 specifies that dividing zero by zero signals an invalid operation exception. When an exception is signaled, normal processing may be interrupted, so this division might not produce any result. In many environments, floating-point exceptions just raise a flag recording the exception but normal processing continues. In this case, IEEE 754-2008 specifies the operation produces a quiet NaN. IEEE 754-2008 does not specify the particular bits in the quiet NaN; a system is free to use those bits to encoded diagnostic information or to use them for other purposes.

(In order to focus on NaNs, I have omitted some details, such as what subnormal numbers are, how significands are normalized for level four, and how the leading bit of a significand is known if it is not stored.)

Eric Postpischil
  • 195,579
  • 13
  • 168
  • 312
2

NaN is not a well-defined value, but a set of values

To IEEE, values are abstract mathematical entities, separate from their encodings. For example, a parricular bit pattern may encode a numeric value 42.0. A bit pattern is not a real number but an encoding of one.

NaN is a symbolic entity (not a number, just as the name implies), of which there are two kinds, quiet NaN and signalling NaN. NaN has more than one encoding as a bit pattern.

does it have a well-defined bit pattern or not

IEEE-754 does not mandate any particular bit pattern.

n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243
  • Are you kidding with me? "It is a value (two values actually, quiet NaN and signalling NaN) which have more than one representation. " - from the question it is crystal clear that by value I meant its binary integer representation. And there are different representations for quiet and signaling `NaN`s. In IEEE-754 `NaN` is defined as the exponent field filled with ones. The mantissa can be anything nonzero. – plasmacel Jan 04 '18 at 10:05
  • 1
    @plasmacel What you mean by "value" is not necessarily what the IEEE standard means. I have changed the answer to more cloaely follow IEEE terminology. – n. m. could be an AI Jan 04 '18 at 10:27