• No results found

Common Lisp

In document DRAFT INTERNATIONAL (Page 105-111)

current indicators() CALL IEEE GET STATUS(STATUS VALUE) (?) where i is an expression of type IEEE STATUS TYPE representing an indicator.

E.5 Common Lisp

The programming language Common Lisp is defined by ANSI X3.226-1994, Information Technol-ogy – Programming Language – Common Lisp [42].

An implementation should follow all the requirements of LIA-1 unless otherwise specified by this language binding.

The operations or parameters marked “†” are not part of the language and must be provided by an implementation that wishes to conform to LIA-1. For each of the marked items a suggested identifier is provided.

Common Lisp does not have a single datatype that corresponds to the LIA-1 datatype Boolean.

Rather, NIL corresponds to false and T corresponds to true.

Every implementation of Common Lisp has one unbounded integer datatype. Any mathemat-ical integer is assumed to have a representation as a Common Lisp data object, subject only to total memory limitations. Thus, the parameters boundedI and moduloI are always false, and the parameters boundedI, moduloI, maxintI, and minintI need not be provided.

The LIA-1 integer operations are listed below, along with the syntax used to invoke them:

eqI(x, y) (= x y) ?

neqI(x, y) (/= x y) ?

lssI(x, y) (< x y) ?

leqI(x, y) (<= x y) ?

gtrI(x, y) (> x y) ?

geqI(x, y) (>= x y) ?

(the floor, ceiling, round, and truncate can also accept floating point arguments) (multiple-value-bind (flr md) (floor x y)) ?

quotI(x, y) flr or (floor x y) ?

modI(x, y) md or (mod x y) ?

(multiple-value-bind (rnd rm) (round x y)) ?

ratioI(x, y) rnd or (round x y) ?

residueI(x, y) rm

(multiple-value-bind (ceil pd) (ceiling x y)) ?

groupI(x, y) ceil or (ceiling x y) ?

padI(x, y) (- pd)

(multiple-value-bind (trunc rest) (ceiling x y)) ?

truncdivI(x, y) trunc or (truncate x y) ? (bad sem., not LIA-1!)

truncremI(x, y) rest or (rem x y) ? (bad sem., not LIA-1!)

where x and y are expressions of type integer.

Common Lisp has four floating point types: short-float, single-float, double-float, and long-float. Not all of these floating point types must be distinct.

The LIA-1 parameters for the floating point types can be accessed by the following constants and inquiry functions.

where x is of type short-float, single-float, double-float or long-float, and T is the string short-float, single-float, double-float, or long-float as approriate.

The LIA-1 derived constants for the floating point datatype can be accessed by the following syntax:

fmaxF most-positive-T ?

fminNF least-positive-normalized-T ?

fminF least-positive-T ?

epsilonF T -epsilon ?

rnd errorF T -rounding-error † (partial conf.)

rnd styleF rounding-style † (partial conf.)

NOTE – LIA-1 requires sign symmetry in the range of floating point numbers. Thus the Common Lisp constants of the form *-negative-* are not needed since they are simply the negatives of their *-positive-* counterparts.

The value of the parameter rounding-style is an object of type rounding-styles. The values of rounding-styles have the following names corresponding to LIA-1 rnd styleF values:

nearesttiestoeven nearesttiestoeven †

nearest nearest †

truncate truncate †

other other †

The LIA-1 floating point operations are listed below, along with the syntax used to invoke them:

(multiple-value-bind (rnd rm) (round x y)) ?

residueF(x, y) rm

truncF,I(x, n) (truncate-float x n) †

roundF,I(x, n) (round-float x n) †

where x and y are data objects of the same floating point type, and n is of integer type.

Arithmetic value conversions in Common Lisp can be explicit or implicit. The rules for when implicit conversions are done is implementation defined.

convertI→I00(x) (format nil "~wB" x) ?(binary) convertI→I00(x) (format nil "~wO" x) ?(octal) convertI→I00(x) (format nil "~wD" x) ?(decimal) convertI→I00(x) (format nil "~wX" x) ?(hexadecimal) convertI→I00(x) (format nil "~r, wR" x) ?(radix r)

convertI→I00(x) (format nil "~@R" x) ?(roman numeral)

floorF →I(y) (floor y) ?

where x is an expression of type INT, y is an expression of type FLT. Conversion from string to numeric value is in Common Lisp done via a general read procedure, which reads Common Lisp

‘S-expressions’.

Common Lisp provides non-negative numerals for all its integer and floating point datatypes in base 10.

There is no differentiation between the numerals for different floating point datatypes, nor between numerals for different integer datatypes, and integer numerals can be used for floating point values.

Common Lisp does not specify numerals for infinities and NaNs. Suggestion:

+∞

+∞

+∞ infinity-FLT †

qNaN nan-FLT †

sNaN signan-FLT †

as well as string formats for reading and writing these values as character strings.

Common Lisp has a notion of ‘exception’.

However, Common Lisp has no notion of compile time type checking, and an operation can return differently typed values for different arguments. When justifiable, Common Lisp arithmetic operations return a rational or a complex floating point value rather than giving a notification, even if the argument(s) to the operation were not complex. For instance, (sqrt -1) (quietly) returns a representation of 0 + i.

The notification method required by Common Lisp is alteration of control flow as described in 6.2.2. Notification is accomplished by signaling a condition of the appropriate type. LIA-1 exceptional values are represented by the following Common Lisp condition types:

overflow floating-point-overflow ?

underflow floating-point-underflow ?

invalid arithmetic-error ?

infinitary division-by-zero ?

absolute precision underflowabs-precision-underflow †, LIA-2, -3

inexact inexact †, IEC 60559

An implementation that wishes to conform to LIA-1 must signal the appropriate condition type whenever an LIA-1 exceptional value would be returned, and must provide a default handler for use in the event that the programmer has not supplied a condition handler.,.,.,.,

Annex F (informative)

Example of a conformity statement

This annex presents an example of a conformity statement for a hypothetical implementation of Fortran. The underlying hardware is assumed to provide 32-bit two’s complement integers, and 32- and 64-bit floating point numbers. The hardware floating point conforms to the IEEE 754 (IEC 60559) standard.

The sample conformity statement follows.

This implementation of Fortran conforms to the following standards:

ISO/IEC 1539:1991, Information technology – Programming languages – FORTRAN ANSI/IEEE Std 754-1985, IEEE Standard for Binary Floating-Point Arithmetic (also

known as IEC 60559:1989, Binary floating-point arithmetic for microprocessor systems)

ISO/IEC 10967-1:1994, Language independent arithmetic – Part: 1 Integer and floating point arithmetic (LIA-1)

It also conforms to the suggested Fortran binding standard in E.4 of LIA-1.

Only implementation dependent information is directly provided here. The information in the suggested language binding standard for Fortran (see E.4) is provided by reference. Together, these two items satisfy the LIA-1 documentation requirement.

F.1 Types

There is one integer type, called integer. There are two floating point types, called real and double.

In document DRAFT INTERNATIONAL (Page 105-111)