home *** CD-ROM | disk | FTP | other *** search
- Support for Floating Point in Draco V 1.2
-
-
- I. The Format Used
-
- Draco V 1.2 supports the Amiga's IEEE double precision floating point
- package as the type 'float'. The support is quite complete, and
- probably offers a few features not available with any other Amiga
- programming system. Each such floating point value occupies 8 bytes of
- storage, and contains roughly 16 decimal digits of accuracy. The range
- of values supported is approximately 10E-300 to 10E+300. The Amiga
- software floating point library does not appear to fully support the
- IEEE format in the areas of unnormalized numbers, NaN's and infinities.
- The Draco compiler and run-time system support these elements to the
- extent that they are able. On a system with a math chip (MC68881 or
- MC68882) installed and configured, support for these features should be
- available. I have no idea what you would have to do to setup the chip
- to recognize and signal NaN's, but it is likely that you will have to
- do some inline code (e.g. Draco's 'code' construct) to enable the
- desired behavior.
-
-
- II. Compiler Support
-
- The compiler recognizes and translates floating point numbers in source
- programs. These can be in E-format (e.g. 0.618e-103), F-format (e.g.
- -278.349) or in a special format for special values. In particular, a
- floating point constant must have exactly one decimal point. For E
- format, the '+' sign for the exponent is optional, and the exponent can
- be any number of decimal digits. The special forms '0fNaN' and '0fInf'
- are recognized to generate IEEE NaN's and infinities. Negative values
- can be generated using the unary '-' operator with these constants.
- Floating point constants can be given explicitly in hexadecimal, using
- the form '0fxYYYYYYYYYYYYYYYY'. There must be exactly 16 hexadecimal
- digits given in this form. In the special forms, case is not
- significant.
-
- Compile-time evaluation of floating point expressions is supported for
- the following operators: unary '+', unary '-', unary '|', binary '+',
- binary '-', binary '*' and binary '/'. Also available are the
- constructs 'fix' and 'flt', which convert from float to long and from
- long to float, respectively. The syntax of this is the keyword followed
- by the argument in parentheses. All of these are done by calling the
- appropriate routine in the Amiga's IEEE floating point library. Note
- that at both compile time and at run time, the library routines are
- called for the unary '-' and unary '|' operations, even though these
- can be done by simply flipping or clearing a bit. On a system with a
- math chip, these operations can cause exceptions, so should be given to
- the chip to execute.
-
- When compiling a source program that contains a floating point constant
- in E or F format, or which does compile-time floating point evaluation,
- the compiler needs to open 'mathieeedoubbas.library', which should be
- located in your 'libs:' directory. The compiler and run-time libraries
- have been tested using the version of this library that comes with V1.3
- of the Amiga operating system, but they should also work with earlier
- versions of the library.
-
-
- III. Run-Time Support
-
- All of the operations mentioned above for compile time are available at
- run-time for floating point values. In addition, Draco include file
- 'float.g' defines some handy values and declares the library routines
- 'sin', 'cos', 'tan', 'atan', 'asin', 'acos', 'sinh', 'cosh', 'tanh',
- 'exp', 'log', 'log10', 'sqrt' and 'pow', all of which are available in
- AmigaDOS V1.3's 'mathieeedoubtrans.library' library, which should also
- be located in your 'libs:' directory. Note that the compiler itself
- does not use this library, but that the standard floating point startup
- code attempts to open the trancendental library along with the standard
- math library.
-
- Run-time input and output of floating point values is fully supported.
- On input, any of the formats accepted by the compiler is acceptable,
- and the leading '0f' is optional on the special forms. New syntax has
- been added to the compiler's 'write' and 'writeln' formatting options
- to support floating point output. There are essentially 3 output
- formats that can be used. They are 'f', for F-format, 'e' for E-format,
- and 'g' for F-format if the number fits nicely, else E-format. Each
- form can take two integral expressions as size and digits specifiers,
- with both defaulting to 0.
-
- The exact rules for output are as follows: (in all cases, if an
- explicit length is given, and the formatted value does not fit in that
- length, then that number of '*'s are printed)
-
- if the high order 12 bits (excluding the high, sign, bit) are all
- ones, then the value is considered to be special. If the remainder
- of the bits other than the sign bit are all 0, then the number is
- assumed to be an infinity, and either '+Inf' or '-Inf' will be
- printed. All other special values are printed as '+NaN' or '-NaN'.
-
- otherwise:
-
- if 'g' format was specified and the decimal exponent is less
- than -5 or greater than +10, then use 'e' format instead.
-
- 'e' format:
-
- if neither the length nor digits were specified, then all
- trailing zeros will be trimmed, producing an output as
- short as possible. If the number of digits is specified,
- then that number of digits is used, regardless of the
- length given. If the length is given, but no digits value
- is given, then length - 8 digits will be printed. (8
- characters are needed for -0.E-ddd). If the length was
- given as a negative value, then its positive form is used
- and an explicit '+' is used on the front of positive
- numbers, else a space is used. When both the length and the
- desired number of digits are given, any extra space needed
- is padded on the left with spaces.
-
- e.g. value format result
- 1.0 e " 0.1e+001"
- 1.e30 e " 0.1e+031"
- 23.45 e:6 "******"
- 23.45 e:15 " 0.2345000e+002"
- 23.45 e:-15:4 " +0.2345e+002"
- -87654. e:12 "-0.8765e+005"
-
- 'f' format:
-
- the rules for producing an F-format value are quite
- complicated. The essence is a desire to always have the
- decimal points line up for any values with the same format.
- A negative length will cause padding on the left with '0's
- instead of with spaces. A negative digit count will cause
- padding on the right with '0's instead of spaces. A leading
- '+' sign is never printed, nor is space left for one. Zeros
- for both values (or neither given) will cause no padding,
- and the value is rounded to a default of 5 digits. Note
- that if only one length/digits specification is given, then
- it is the digits specification, and the resulting length
- will depend on the value printed. The most control over the
- output format occurs when both values are specified, and it
- is this form that is normally used for tabular output.
-
- e.g. value format result
- 1.0 f "1.0"
- 1.e20 f "99999999999999970000.0"
- 23.45 f "23.45"
- 23.45 f:6 "23.45 "
- 23.45 f:-6:2 "023.45"
- 23.45 f:6:-3 "23.450"
- 23.45 f:-10:-5 "0023.45000"
- .00000001 f "0.00000001"
- .00000001 f:10 "0.00000001 "
- .00000001 f:-15:-10 "0000.0000000100"
- .00000001 f:0:-10 "0.0000000100"
- .00000001 f:0:-8 "0.00000001"
- .00000001 f:0:-7 "0.00000001"
- .00000001 f:0:7 "0.00000001"
- 123.12345678 f:0:8 "123.12345678"
- 123.12345678 f:0:4 "123.1235"
- 123.12345678 f:10:4 " 123.1235"
- -123.12345678 f:10:4 " -123.1235"
- -123.12345678 f "-123.12"
- -123.12345678 f:10:0 " -123."
- -123.12345678 f:0:10 "-123.12345678"
- 0fNaN f +NaN
- -0fInf f -Inf
-
- Note that because of the way the compiler generates code
- for F-format output, 'f' is equivalent to 'f:0', which is
- equivalent to 'f:0:0'. If the format that you want is a
- minimum length one (normally, length = 0), but with no
- digits after the decimal point, then the following is
- suggested:
-
- write(fix(floatValue), '.');
-
-
- IV. The Complex Number Package
-
- A complex number operator-type package is included with this
- distribution. There are four files of interest. 'drlib/complex.lib' is
- the library file which implements the package. It is compiled from the
- source in 'src/complex.d' (the resulting 'complex.r' file is simply
- copied to 'drlib:' as 'complex.lib'). 'complex.g' is the include file
- in 'drinc:' which defines the package to its users, and
- 'src/complexTest.d' is a simple test program that demonstrates how to
- use the package.
-
- My thanks to Don Reble for the complex trancendental functions.
-