Ask Reuben

Big Numbers

What is the biggest BIGINT? 

Why is my BIGINT being altered in JSON?

The Genero documentation gives the biggest number for various integer datatypes

TINYINT 127 (27 -1)

SMALLINT 32,767 (215 -1)

INTEGER 2,147,483,647 (231-1)

BIGINT 9,223,372,036,854,775,807 (263 -1)

Recently had an interesting case where a very big BIGINT was not parsing to JSON correctly.  When we investigated it, the JSON definition of a number uses the IEEE 754 double-precision floating point format.

This format has the following precisions

Integers from −253 to 253 (−9,007,199,254,740,992 to 9,007,199,254,740,992) can be exactly represented
Integers between 253 and 254 = 18,014,398,509,481,984 round to a multiple of 2 (even number)
Integers between 254 and 255 = 36,028,797,018,963,968 round to a multiple of 4

… that is the biggest BIGINT cannot be precisely represented by the IEEE 754 double-precision floating-point format.

Hence if you are using BIGINT and also expect to use JSON or any other library that uses this format for a numerical expression, use caution.

If you want to see this impact, note how you get the following output from the following code … (look at x1 and x2 are they equal or different?)

{"x1":9007199254740992,"x2":9007199254740992}

IMPORT util
MAIN
DEFINE rec RECORD
    x1, x2 BIGINT
END RECORD
DEFINE j util.JSONObject

    LET rec.x1 = util.Math.pow(2,53) 
    LET rec.x2 = rec.x1 + 1

    LET j = util.JSONObject.fromFGL(rec)

    DISPLAY j.toString()
END MAIN