Search code examples
cfloating-pointluafloating-point-conversion

In Lua, what is #INF and #IND?


I'm fairly new to Lua. While testing I discovered #INF/#IND. However, I can't find a good reference that explains it.

What are #INF, #IND, and similar (such as negatives) and how do you generate and use them?


Solution

  • #INF is infinite, #IND is NaN. Give it a test:

    print(1/0)
    print(0/0)
    

    Output on my Windows machine:

    1.#INF
    -1.#IND
    

    As there's no standard representation for these in ANSI C, you may get different result. For instance:

    inf
    -nan