[fpc-pascal] math with infinity and NaN

James Richters james at productionautomation.net
Wed Jun 20 15:58:32 CEST 2018


No, that’s not normal, it's not supposed to give you a runtime error.
Anything that results in an answer that is Not a Number is supposed to be set to NaN, not give you a runtime error 217 and terminate.
Infinity minus itself is undefined and therefore Not a Number and should be set to NaN, but I don't get NaN, I get a fatal runtime error 217.   To answer your question:  if you know Inf + Inf = Inf and you know Inf - Inf = Nan then Properly evaluating from left to right: Inf + Inf - Inf = Inf - Inf = NAN     or if you want to do it the other way:  inf - inf + inf  = NaN + Inf = NaN

(+inf) + (+inf) should and does give you (+inf)
(-inf) + (-inf) should and does give you (-inf)
(+inf) - (+inf) should give you (NAN)  but it gives you Runtime Error 217
(-inf) - (-inf) should give you (NAN)  but it gives you Runtime Error 217
(+inf) + (-inf) should give you (NAN)  but it gives you Runtime Error 217
(-inf) + (+inf) should give you (NAN)  but it gives you Runtime Error 217

Snip from refrence at: https://en.wikipedia.org/wiki/NaN 
Operations generating NaN:
There are three kinds of operations that can return NaN:

1. Operations with a NaN as at least one operand.

2. Indeterminate forms: 
      a. The divisions (±0) / (±0) and (±∞) / (±∞).
      b. The multiplications (±0) × (±∞) and (±∞) × (±0).
      c. The additions (+∞) + (−∞), (−∞) + (+∞) and equivalent subtractions (+∞) − (+∞) and (−∞) −  (−∞).
      d. The standard has alternative functions for powers: 
            The standard pow function and the integer exponent pown function define 0⁰, 1∞, and ∞⁰ as 1.
            The powr function defines all three indeterminate forms as invalid operations and so returns NaN.

3. Real operations with complex results, for example: 
      The square root of a negative number.
      The logarithm of a negative number.
      The inverse sine or cosine of a number that is less than −1 or greater than 1.

#2c clearly defines that NaN is set for the above conditions that are failing with a runtime error 217

Also reference:
https://www.philforhumanity.com/Infinity_Minus_Infinity.html


James
-----Original Message-----
From: fpc-pascal [mailto:fpc-pascal-bounces at lists.freepascal.org] On Behalf Of Marco van de Voort
Sent: Wednesday, June 20, 2018 9:21 AM
To: FPC-Pascal users discussions <fpc-pascal at lists.freepascal.org>
Subject: Re: [fpc-pascal] math with infinity and NaN

In our previous episode, C Western said:
> > I can do things like +infinity*2 and +infinity-3 and even 
> > sqr(infinity) and power(infinity,10) the results are still +Inf which is expected?
> >  ??but I can?t do anything involving subtracting infinity from 
> > infinity.?

Isn't that normal? Otherwise, what would inf+inf-inf be if you know that
(inf+inf) =inf


_______________________________________________
fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal



More information about the fpc-pascal mailing list