gams:precision_of_data_within_gams

Within GAMS numbers are stored internally in a 64-bit IEEE double-precision value on all platforms. The range of normalized values that can be represented by these doubles is [2.2251e-308, 1.7977e+308] but GAMS restricts the range of allowed values to a subset of these. For example, GAMS considers results larger than 1e299 to be overflows or infinity.

There is also limit to the precision of these doubles - the relative error between any real number in the normalized range and the nearest representable double is at most 2.2204e-016. In practice this means values will have at most 15 or 16 decimal digits of accuracy. GAMS will never print more than 15 decimals. When GAMS reads numbers it will guarantee 15 digits of precision and will give an error message ($103) when getting a number with more than 16 digits, since there will be a loss of precision in storing the result and the extra digits are essentially meaningless:

- The option $offdigit can be used to read in data which has more than 16 digits
- The
`display`

statement only prints up to 8 decimals (3 by default) to the listing file. Use the option`decimals = n`

to change it the n decimals. - To get maximal precision on a put statement one should force 'scientific' format with plenty of room as shown below
- GDX in and out does not drop any precision, it takes the floating point number bit by bit.

$eolcom # set digits / 14 * 18 /; parameter v(digits) / 14 1.2345678901234 15 1.23456789012345 16 1.234567890123456 $offdigit 17 1.2345678901234569 18 1.23456789012345678 /; display 'default number of decimal digits', v; # by default GAMS only displays 3 digits option decimals=8; # we can't get more display 'maximal number of decimal digits for display', v; file output /output.txt/; output.nr = 2 ; #'rounding option' used to force e format output.nd = 15 ; # or larger output.nw = 0 ; # width as required put output; loop(digits, put v(digits)/; ) ; execute_unload 'dump.gdx' v execute 'gdxdump dump.gdx NoHeader >dump.txt'

IMPRESSUM / LEGAL NOTICE
PRIVACY POLICY
gams/precision_of_data_within_gams.txt · Last modified: 2008/02/07 05:25 by franz