In this section, LIA-1 refers to ISO/IEC 10967-1:1994 Information Technology - Language Independent Arithmetic - Part 1: Integer and floating-point arithmetic.
The C and Fortran 95 compilers (cc and f95) contained in the Sun Studio compilers release conform to LIA-1 in the following senses (paragraph letters correspond to those in LIA‐1 section 8):
The LIA-1 conformant types are C int and Fortran INTEGER. Other types can conform as well, but they are not specified here. Further specifications for specific languages await language bindings to LIA-1 from the cognizant language standards organizations.
#include <values.h> /* defines MAXINT */ #define TRUE 1 #define FALSE 0 #define BOUNDED TRUE #define MODULO TRUE #define MAXINT 2147483647 #define MININT ‐2147483648 logical bounded, modulo integer maxint, minint parameter (bounded = .TRUE.) parameter (modulo = .TRUE.) parameter (maxint = 2147483647) parameter (minint = ‐2147483648)
C / and %, and Fortran / and mod(), provide DIVtI(x,y) and REMtI(x,y). Also, modaI(x,y) is available with the following code:
int modaI(int x, int y) { int t = x % y; if (y < 0 && t > 0) t ‐= y; else if (y > 0 && t < 0) t += y; return t; }
It is also available with the following code:
integer function modaI(x, y) integer x, y, t t = mod(x, y) if (y .lt. 0 .and. t .gt. 0) t = t ‐ y if (y .gt. 0 .and. t .lt. 0) t = t + y modaI = t return end
The following table shows the notation by which the LIA integer operations can be realized.
Table 43 LIA‐1 Conformance ‐ Notation
|
The following code shows the Fortran notation for signI(x).
integer function signi(x) integer x, t if (x .gt. 0) t=1 if (x .lt. 0) t=‐1 if (x .eq. 0) t=0 return end
By default, when no optimization is specified, expressions are evaluated in int (C) or INTEGER (Fortran) precision. Parentheses are respected. The order of evaluation of associative unparenthesized expressions such as a + b + c or a * b * c is not specified.
Include the definitions in b. PARAMETERS (LIA 5.1): in your source code.
Integer exceptions are x/0 and x%0 or mod(x,0). By default, these exceptions generate SIGFPE. When no signal handler is specified for SIGFPE, the process terminates and dumps memory.
signal(3) or signal(3F) can be used to enable user exception handling for SIGFPE.