Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - numeric numeric constants http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 numeric             Numeric constants
------------------------------------------------------------------------------

 Syntax
   [-]decdigits[I|UI|L|UL]
   [-]decdigits.decdigits
   bindigitsB
   0xhexdigits
   [-]decdigits[.decdigits]e[-]decdigits

 Arguments
   decdigits is a sequence of the decimal digits 0-9.

   bindigits is a maximum 32 character long sequence of the binary
   digits 0 and 1.

   hexdigits is a 1 to 8 character long sequence of the hexadecimal digits
   0-9 and a-f.

 Description
   Numeric constants are used to represent numeric values of various
   magnitude.

   The cast suffixes I, UI, L, UL can be used to change the default
   constant numeric type for a particular value that the compiler
   assigns according to the magnitude of the number. Casting is
   important when a constant should be different from what is given by
   the -C<n> compiler switch.

   The cast suffixes can not be used when initializing structures. In this
   case the definition of the structure itself guarantees the correct
   assignment of the members.

 Example
   #define EXAMPLE_CONSTANT
   #include example.hdr

   proc Test_numeric
   
   // integer constants
   ? 5
   ? 1234567
   ? -345
   ?
   // floating point constants
   ? 34.78
   ? -2.1
   ?
   // base 10 exponential constants
   ? 3e5
   ? -12.7e-3
   ?
   // binary constants
   ? 101101B
   ? 11111111111111111111111111111111B
   ?
   // hexadecimal constants
   ? 0x0
   ? 0xff00
   ? 0xdeafbabe
   ? 0xffffffff
   ?
   // type cast
   ? 10 * 20          // wrong result
   ? 10 * 20UI        // correct result
   ? 5000 * 50        // wrong result
   ? 5000 * 50UL      // correct result
   
   endproc

   proc main
   Test_numeric()
   endproc

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson