## Standards Compliance |
## F |

The compilers, header files, and libraries in the Sun WorkShop Compilers products for Solaris support multiple standards: System V Interface Definition (SVID), Edition 3, X/Open and ANSI C. Accordingly, the mathematical library libm and related files have been modified so that C programs comply with the standards. Users' programs are usually not affected, because the differences primarily involve exception handling.

This appendix has the following organization:

Because these environments treat floating-point exceptions in varied ways, uniformity could only be imposed by checking arguments and results in software before and after each atomic floating-point instruction. Because this has too great an impact on performance, SVID does not specify the effect of floating-point exceptions such as division by zero or overflow.

Operations implemented by subroutines are slow compared to single atomic floating-point instructions; extra error checking of arguments and results has little performance impact; so such checking is required by the SVID. When exceptions are detected, default results are specified, errno is set to EDOM for improper operands, or ERANGE for results that overflow or underflow, and the function matherr() is called with a record containing details of the exception. This costs little on the machines for which UNIX was originally developed, but the value is correspondingly small because the far more common exceptions in the basic operations +, -, * and / are completely unspecified.

Elements of IEEE exception handling include suitable default results and interruption of computation only when requested in advance.

Function |
errno |
errormessage |
SVID |
X/Open |
IEEE |

- The ANSI C compiler switches
`-Xt, -Xa, -Xc, -Xs,`among other things, control the level of standards compliance that is enforced by the compiler. Refer to`cc`(1) for a description of these switches. - As far as
`libm`is concerned,`-Xt`and`-Xa`cause SVID and X/Open behavior, respectively.`-Xc`corresponds to strict ANSI C behavior.

- An additional switch
`-<x>libmieee`, when specified, returns values in the spirit of IEEE 754. The default behavior for`libm`and`libsunmath`is to be SVID-compliant on SunOS 5.x.

- For strict ANSI C (
`-Xc`),`errno`is set always,`matherr()`is not called, and the X/Open value is returned. - For SVID (
`-Xt`or`-Xs`), the function`matherr()`is called with information about the exception. This includes the value that is the default SVID return value.

- A user-supplied
`matherr()`could alter the return value; see`matherr`(3m). If there is no user-supplied`matherr()`,`libm`sets`errno`, possibly prints a message to standard error, and returns the value listed in the SVID column of Table F-1 on page 229.

- For X/Open (
`-Xa`), the behavior is the same as for the SVID, in that`matherr()`is invoked and`errno`set accordingly. However, no error message is written to standard error, and the X/Open return values are the same as IEEE return values in many cases. - For the purposes of
`libm`exception handling,`-Xs`behaves the same as`-Xt`. That is, programs compiled with`-Xs`use the SVID compliant versions of the`libm`functions listed in Table F-1 on page 229. - For efficiency, programs compiled with in-line hardware floating-point
do not do the extra checking required to set
`EDOM`or call`matherr()`if`sqrt`encounters a negative argument.`NaN`is returned for the function value in situations where`EDOM`might otherwise be set.

- Thus, C programs that replace
`sqrt()`function calls with`fsqrt[sd]`instructions conform to the IEEE Floating-Point Standard, but may no longer conform to the error handling requirements of the System V Interface Definition.

PLOSS and TLOSS reflect instead limitations of particular algorithms for
`fmod` and for trigonometric functions that suffer abrupt declines
in accuracy at definite boundaries.

Like most IEEE implementations, the `libm` algorithms do not suffer such abrupt declines, and so do not signal PLOSS. To satisfy the dictates of SVID compliance, the Bessel functions do signal TLOSS for large input arguments, although accurate results can be safely calculated.

The implementations of `sin`, `cos`, and `tan`
treat the essential singularity at infinity like other essential singularities
by returning a `NaN` and setting `EDOM` for infinite arguments.

Likewise SVID specifies that `fmod`(`x,y`) is be zero if
`x/y` overflows, but the `libm` implementation of `
fmod`, derived from the IEEE remainder function, does not compute
`x/y` explicitly and hence always delivers an exact result.

The C and Fortran-77 compilers (`cc` and `f77`) contained in the Sun WorkShop Compilers 4.2 release for Solaris conform to LIA-1 in the following senses (paragraph letters correspond to those in LIA-1 section 8):

a. TYPES (LIA 5.1): The LIA-1 conformant types are C int and Fortran INTEGER. Other types may 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)d. DIV/REM/MOD (LIA 5.1.3):

C / and %, and Fortran / and mod(), provide DIVtI(x,y) and REMtI(x,y). Also, modaI(x,y) is available with this 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;

}or this:

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

endi. NOTATION (LIA 5.1.3): The following table shows the notation by which the LIA integer operations may be realized.

LIA |
C |
Fortran if different |

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

endj. EXPRESSION EVALUATION: 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.

k. METHOD OF OBTAINING PARAMETERS: Include the definitions above in the source code.

n. NOTIFICATION: Integer exceptions are x/0 and x%0 or mod(x,0). By default, these exceptions generate `SIGFPE` on SPARC and Intel and `SIGILL` on PowerPC. When no signal handler is specified for `SIGFPE` or `SIGILL`, the process terminates and dumps memory.

o. SELECTION MECHANISM: signal(3) or signal(3F) may be used to enable user exception handling for `SIGFPE` or `SIGILL`.