INTERFACEModula-3 target descriptionTFloat ;
This interface provides simulations of the target machine's floating-point operations.
Unless otherwise specified, the arithmetic operations defined below return TRUE if they succeed in producing a new target value, otherwise they return FALSE.
FROM Target IMPORT Float, Precision; CONST ZeroR = Float { Precision.Short, 0, 0.0x0 }; ZeroL = Float { Precision.Long, 0, 0.0x0 }; ZeroX = Float { Precision.Extended, 0, 0.0x0 }; PROCEDURE New (READONLY chars: ARRAY OF CHAR; pre: Precision; VAR f: Float): BOOLEAN;
converts 'chars' to a floating point value with the specified precision. Note: regardless of the precision, the exponent must be started by the character 'e'.
PROCEDURE Prec (READONLY f: Float): Precision;
returns the precision of 'f'
PROCEDURE Add (READONLY a, b: Float; VAR f: Float): BOOLEAN;
returns 'a + b' unless there's an overflow
PROCEDURE Subtract (READONLY a, b: Float; VAR f: Float): BOOLEAN;
returns 'a - b' unless there's an overflow
PROCEDURE Multiply (READONLY a, b: Float; VAR f: Float): BOOLEAN;
returns 'a * b' unless there's an overflow
PROCEDURE Divide (READONLY a, b: Float; VAR f: Float): BOOLEAN;
returns 'a / b' unless there's an overflow
PROCEDURE Mod (READONLY a, b: Float; VAR f: Float): BOOLEAN;
returns 'a MOD b' unless there's an overflow
PROCEDURE EQ (READONLY a, b: Float): BOOLEAN;
returns 'a = b'
PROCEDURE LT (READONLY a, b: Float): BOOLEAN;
returns 'a < b' unless there's an overflow
PROCEDURE LE (READONLY a, b: Float): BOOLEAN;
returns 'a <= b' unless there's an overflow
PROCEDURE FloatF (READONLY a: Float; p: Precision; VAR f: Float): BOOLEAN;
returns 'FLOAT (a, p)' unless there's an overflow
PROCEDURE FloatI (READONLY i: INTEGER; p: Precision; VAR f: Float): BOOLEAN;
returns 'FLOAT (i, p)' unless there's an overflow
PROCEDURE Trunc (READONLY a: Float): INTEGER;
returns 'TRUNC(a)'
PROCEDURE Round (READONLY a: Float): INTEGER;
returns 'ROUND(a)'
PROCEDURE Floor (READONLY a: Float): INTEGER;
returns 'FLOOR(a)' unless there's an overflow
PROCEDURE Ceiling (READONLY a: Float): INTEGER;
returns 'CEILING(a)'
PROCEDURE ToChars (READONLY f: Float; VAR buf: ARRAY OF CHAR): INTEGER;
converts 'f' to a printable string in 'buf'. Returns the number of characters in the string. Returns -1 if 'buf' is too short.
TYPE Byte = [0..255]; PROCEDURE ToBytes (READONLY f: Float; VAR buf: ARRAY OF Byte): INTEGER;
converts 'f' to an array of bytes in 'buf'. Returns the number of bytes in 'buf'. Returns -1 if 'buf' is too short.
PROCEDURE FromBytes (READONLY buf: ARRAY OF Byte; p: Precision; VAR f: Float);
converts the array of bytes in 'buf' to a float 'f' with precision 'p'.
END TFloat.