0

(reproducible example is added)

The maximum positive double (floating point) number in computer in my 64-bit OS and 32-bit R is:

.Machine$double.xmax # 1.797693e+308

So, the following is TRUE:

is.finite(1.797683e+308) # TRUE; here, as argument I used 1.797683e+308

So, then what is the max real number in computer I can get TRUE as a result of is.finite?

Erdogan CEVHER
  • 1,788
  • 1
  • 21
  • 40
  • `1.797683e+308` is a rounded representation of the `.Machine$double.xmax`. Please read https://stackoverflow.com/a/9508558/5414452 – jogo Apr 26 '19 at 08:10
  • @jogo, what is its unrounded state? Also, I want to see `is.finite(x)` to be `TRUE` and `is.finite(x+1)` `FALSE`. I want to find that limit x. – Erdogan CEVHER Apr 26 '19 at 08:13
  • Read the text and the texts linked in the text: you have to explore the internal representation of the foating point numbers (using base 2). – jogo Apr 26 '19 at 08:15
  • 1
    What you define in the preceding comment is not the maximum real number that can be represented. Please clarify your question. – Roland Apr 26 '19 at 08:17
  • @ErdoganCEVHER To see that for a number `x` near `.Machine$double.xmax` x != (x+1) assumes that the internal representation of the floating point number can store 308 digits of the mantissa (converted to the decimal system). This is not the case. So for a number `x` near `.Machine$double.xmax` you will get always TRUE for `x == (x+1)` – jogo Apr 26 '19 at 08:22
  • @Roland, Is the unrounded version of 1.797693e+308 maximum real number? – Erdogan CEVHER Apr 26 '19 at 08:23
  • 1
    https://en.wikipedia.org/wiki/Double-precision_floating-point_format The internal representation of the `.Machine$double.xmax` is `0111 1111 1110 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111` = 2^1023 * (2 − 2^(−52)) – jogo Apr 26 '19 at 09:06
  • 1
    The least bit of the `.Machine$double.xmax` has the value 2^(1023-52) (i.e. ca. 1.99584*10^292) – jogo Apr 26 '19 at 09:22
  • `is.finite(1.99584*10^292) # TRUE`; and `is.finite(1.99584*10^293) # TRUE`; and `is.finite(1.99584*10^295) # TRUE`. Then, what is the job of `is.finite` then? – Erdogan CEVHER Apr 26 '19 at 10:36
  • I squeezed the `Inf`: `is.finite(1.99584*10^307) # TRUE`; and `is.finite(1.99584*10^308) # FALSE`. – Erdogan CEVHER Apr 26 '19 at 10:39
  • 2
    If the question is about the argument to `is.finite` represented in the floating-point format, the answer is indeed 2^1023•(2-2^-52). However, if we ask what is the largest number we can write in the source text for which `is.finite` will evaluate to true, then any number less than 2^1023•(2-2^-53) ought to round down to 2^1023•(2-2^-52) and produce true, so there would be no largest number with that property—you could always get a little closer to 2^1023•(2-2^-53). – Eric Postpischil Apr 26 '19 at 12:09
  • 5
    However, when I try this [online R service](https://www.jdoodle.com/execute-r-online), it returns true for `0x1.fffffffffffff7fp1023` but false for `0x1.fffffffffffff7ffp1023`, so it looks like the parser is imperfect. – Eric Postpischil Apr 26 '19 at 12:10
  • Also, I found that `is.finite(1.797693e+308 + 10^301) # TRUE` and `is.finite(1.797693e+308 + 10^302) # FALSE`. – Erdogan CEVHER Apr 26 '19 at 12:26
  • `2^1023*(2-2^-52) # 1.797693e+308` whereas the math equivalent `2^1024 - 2^971 # Inf`. So, a care is needed. – Erdogan CEVHER Apr 30 '19 at 12:35

1 Answers1

0

The following is a partial answer of the question:

is.finite(179769313486231570838400602864442228000008602082842266064064680402680408280648240046204888888288080622822420842246006644866884860462806420066668022046626024066662068886808602862886866800048228686262462640668044406484606206082824406288200264266406808068464046840608044222802268424008466606886862062820068082689.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999) # TRUE    
is.finite(179769313486231570838400602864442228000008602082842266064064680402680408280648240046204888888288080622822420842246006644866884860462806420066668022046626024066662068886808602862886866800048228686262462640668044406484606206082824406288200264266406808068464046840608044222802268424008466606886862062820068082689.999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999990) # FALSE; One more digit ("0") at the end of the decimal point killed it!
is.finite(179769313486231570838400602864442228000008602082842266064064680402680408280648240046204888888288080622822420842246006644866884860462806420066668022046626024066662068886808602862886866800048228686262462640668044406484606206082824406288200264266406808068464046840608044222802268424008466606886862062820068082690) # TRUE (For math, it is absurd this to be returned "TRUE"). Why is this returned TRUE instead of FALSE?
is.finite(1797693134862315708384006028644422280000086020828422660640646804026804082806482400462048888882880806228224208422460066448668848604628064200666680220466260240666620688868086028628868668000482286862624626406680444064846062060828244062882002642664068080684640468406080442228022684240084666068868620628200680826990) # FALSE

The above three lines of code indicates that is.finite does not work as expected from the mathematical point of view!

I tested this situation in the following online R servers and I get the same "TRUE, FALSE, TRUE" result as well:

Online R Servers:

https://paiza.io/projects/pTHIb6DfqKIFnBFBjEykdQ?language=r    
https://www.tutorialspoint.com/execute_r_online.php    
https://rdrr.io/snippets/    
https://rextester.com/l/r_online_compiler    
https://www.jdoodle.com/execute-r-online  

Once I find the logic behind this situation, I'll add it here as well.

Erdogan CEVHER
  • 1,788
  • 1
  • 21
  • 40