TABLE OF CONTENTS mathieeedoubbas.library/--Background-- mathieeedoubbas.library/IEEEDPAbs mathieeedoubbas.library/IEEEDPAdd mathieeedoubbas.library/IEEEDPCeil mathieeedoubbas.library/IEEEDPCmp mathieeedoubbas.library/IEEEDPDiv mathieeedoubbas.library/IEEEDPFix mathieeedoubbas.library/IEEEDPFloor mathieeedoubbas.library/IEEEDPFlt mathieeedoubbas.library/IEEEDPMul mathieeedoubbas.library/IEEEDPNeg mathieeedoubbas.library/IEEEDPSub mathieeedoubbas.library/IEEEDPTst mathieeedoubbas.library/--Background-- mathieeedoubbas.library/--Background-- PURPOSE The mathieeedoubbas.library provides basic arithmetic functions for handling double precision IEEE numbers. If a FPU is found present in the system, this library uses the FPU for calculations. Otherwise, the CPU will provide a suitable emulation. The 68040 and 68060 built-in FPUs do not provide all instructions that the 68881/882 FPUs implement, and hence some of their instructions have to be emulated in software. This works either by the FPU specific trap vectors that have been installed by the 68040 or 68060.library on boot-up, or - if available - by the fpsp.resource which is optionally linked into the system by the 680?0 libraries. The advantage of the resource solution is that it does not require the overhead caused by the exception processing. All this - complete CPU usage, FPU usage plus optional fpsp.resource support - is completely transparent to the user of this library. As of V45 of this library, the mathieee.resources are no longer supported. It was felt that this solution was never very popular, neither very fast compared to a coprocessor interface, and highly obsolete. CAVEATS The library base of the mathieeedoubbas.library MUST NOT be shared among tasks. The reason for this restriction is that the library open vector requires to initialize the FPU properly for the caller's task context. Hence, you may not open this library in one task, pass the library base over and use it from another task as the FPU initialization would not be run for the second task. You must re-open the library again from the second task. This restriction has some implications in using the math IEEE libraries from within other libraries. The first implication is that opening the mathieeedoubbas.library in the LibInit() function IS NOT ENOUGH to ensure proper operation as it will initialize the FPU in the context of the ramlib process loading the library, but not in the context of the caller. This is obviously no use for the task that wants to use IEEE math. Instead, it is recommended to (re-)open the mathieeedoubbas.library once for each LibOpen() within your library, and to close it once for each LibClose() call. As a special rule that is hereby documented, the result code of subsequent OpenLibrary() calls once the library is open will be either NULL on error, or the same library base you received by the initial OpenLibrary(), i.e. in LibInit(). Even though this releases you from the obligation to keep a private copy of the math library base once for each LibOpen(), it does not release you from re-opening the library again for each caller. It is enough to check wether the library opened successfully, and to throw the library base away afterwards, though. It will not deliver task-dependent library bases if it opens successfully. The second implication is that the same, or more restrictions apply to your library then as well, and, in fact, to its full tree of callers. Its library base may not be shared among tasks and must be re-openend for each potential caller. Note that you should document these requirements! The reason is again that the mathieee FPU init code must be run for each task that wants to use your, and hence this math library. Whether you deliver a per-task allocated library base, or one and the same library base is, of course, up to you. To overcome this limitation, your library might want to launch a side task that runs all the mathematical computations such that all callers of your library never enter a single function of the IEEE libs. Then, of course, the IEEE libs should not be opened in LibInit() or LibOpen(), but in the startup code of the side task, and should be closed by its shutdown code. Since the FPU initialization performed by the library depends on the selected precision, i.e. IEEE double vs. IEEE single precision, the third implication is that you must not mix the double and single precision math libraries within the same task. Either, you decide for double precision and stay with it, or you decide for single precision once and for all. You may not perform some calculations in double, and others in single precision as both kinds of libraries require the same hardware - namely the FPU - but with different settings. This goes of course, too, to the full caller tree of a library that runs IEEE functions in the context of its callers. Not following these rules may cause slightly wrong results in the sense that they might not be rounded properly to the selected precision. It may also cause other strange and wonderful side effects that are not mentioned here, and will make the library unreliable from a numerical point of view. BUGS Pre V45 releases could have forgotten to re-initialize the FPU properly if re-opened; in fact, pre-V45 might have even crashed if something in the startup went wrong. mathieeedoubbas.library/IEEEDPAbs mathieeedoubbas.library/IEEEDPAbs NAME IEEEDPAbs -- compute absolute value of IEEE double precision argument SYNOPSIS x = IEEEDPAbs( y ); d0/d1 d0/d1 double x,y; FUNCTION Take the absolute value of argument y and return it to caller. INPUTS y -- IEEE double precision floating point value RESULT x -- IEEE double precision floating point value BUGS SEE ALSO mathieeedoubbas.library/IEEEDPAdd mathieeedoubbas.library/IEEEDPAdd NAME IEEEDPAdd -- add one double precision IEEE number to another SYNOPSIS x = IEEEDPAdd( y , z ); d0/d1 d0/d1 d2/d3 double x,y,z; FUNCTION Compute x = y + z in IEEE double precision. INPUTS y -- IEEE double precision floating point value z -- IEEE double precision floating point value RESULT x -- IEEE double precision floating point value BUGS SEE ALSO IEEEDPSub() mathieeedoubbas.library/IEEEDPCeil mathieeedoubbas.library/IEEEDPCeil NAME IEEEDPCeil -- compute Ceil function of IEEE double precision number SYNOPSIS x = IEEEDPCeil( y ); d0/d1 d0/d1 double x,y; FUNCTION Calculate the least integer greater than or equal to x and return it. This value may have more than 32 bits of significance. This identity is true. Ceil(x) = -Floor(-x). INPUTS y -- IEEE double precision floating point value RESULT x -- IEEE double precision floating point value BUGS SEE ALSO IEEEDPFloor() mathieeedoubbas.library/IEEEDPCmp mathieeedoubbas.library/IEEEDPCmp NAME IEEEDPCmp -- compare two double precision floating point numbers SYNOPSIS c = IEEEDPCmp( y , z ); d0 d0/d1 d2/d3 double y,z; long c; FUNCTION Compare y with z. Set the condition codes for less, greater, or equal. Set return value c to -1 if yz, or 0 if y == z. INPUTS y -- IEEE double precision floating point value z -- IEEE double precision floating point value RESULT c = 1 cc = gt for (y > z) c = 0 cc = eq for (y == z) c = -1 cc = lt for (y < z) BUGS Did not work correctly prior to V45 and might have returned results indicating the wrong order for negative numbers of small absolute value. This has been fixed in V45. SEE ALSO mathieeedoubbas.library/IEEEDPDiv mathieeedoubbas.library/IEEEDPDiv NAME IEEEDPDiv -- divide one double precision IEEE by another SYNOPSIS x = IEEEDPDiv( y , z ); d0/d1 d0/d1 d2/d3 double x,y,z; FUNCTION Compute x = y / z in IEEE double precision. INPUTS y -- IEEE double precision floating point value z -- IEEE double precision floating point value RESULT x -- IEEE double precision floating point value BUGS SEE ALSO IEEEDPMul() mathieeedoubbas.library/IEEEDPFix mathieeedoubbas.library/IEEEDPFix NAME IEEEDPFix -- convert IEEE double float to integer SYNOPSIS x = IEEEDPFix( y ); d0 d0/d1 long x; double y; FUNCTION Convert IEEE double precision argument to a 32 bit signed integer and return result. INPUTS y -- IEEE double precision floating point value RESULT if no overflow occured then return x -- 32 bit signed integer if overflow return largest +- integer For round to zero BUGS SEE ALSO IEEEDPFlt() mathieeedoubbas.library/IEEEDPFloor mathieeedoubbas.library/IEEEDPFloor NAME IEEEDPFloor -- compute Floor function of IEEE double precision number SYNOPSIS x = IEEEDPFloor( y ); d0/d1 d0/d1 double x,y; FUNCTION Calculate the largest integer less than or equal to x and return it. This value may have more than 32 bits of significance. INPUTS y -- IEEE double precision floating point value RESULT x -- IEEE double precision floating point value BUGS SEE ALSO IEEEDPCeil() mathieeedoubbas.library/IEEEDPFlt mathieeedoubbas.library/IEEEDPFlt NAME IEEEDPFlt -- convert integer to IEEE double precision number SYNOPSIS x = IEEEDPFlt( y ); d0/d1 d0 double x; long y; FUNCTION Convert a signed 32 bit value to a double precision IEEE value and return it in d0/d1. No exceptions can occur with this function. INPUTS y -- 32 bit integer in d0 RESULT x is a 64 bit double precision IEEE value BUGS SEE ALSO IEEEDPFix() mathieeedoubbas.library/IEEEDPMul mathieeedoubbas.library/IEEEDPMul NAME IEEEDPMul -- multiply one double precision IEEE number by another SYNOPSIS x = IEEEDPMul( y , z ); d0/d1 d0/d1 d2/d3 double x,y,z; FUNCTION Compute x = y * z in IEEE double precision. INPUTS y -- IEEE double precision floating point value z -- IEEE double precision floating point value RESULT x -- IEEE double precision floating point value BUGS SEE ALSO IEEEDPDiv() mathieeedoubbas.library/IEEEDPNeg mathieeedoubbas.library/IEEEDPNeg NAME IEEEDPNeg -- compute negative value of IEEE double precision number SYNOPSIS x = IEEEDPNeg( y ); d0/d1 d0/d1 double x,y; FUNCTION Invert the sign of argument y and return it to caller. INPUTS y - IEEE double precision floating point value RESULT x - IEEE double precision floating point value BUGS SEE ALSO mathieeedoubbas.library/IEEEDPSub mathieeedoubbas.library/IEEEDPSub NAME IEEEDPSub -- subtract one double precision IEEE number from another SYNOPSIS x = IEEEDPSub( y , z ); d0/d1 d0/d1 d2/d3 double x,y,z; FUNCTION Compute x = y - z in IEEE double precision. INPUTS y -- IEEE double precision floating point value z -- IEEE double precision floating point value RESULT x -- IEEE double precision floating point value BUGS SEE ALSO IEEEDPAdd() mathieeedoubbas.library/IEEEDPTst mathieeedoubbas.library/IEEEDPTst NAME IEEEDPTst -- compare IEEE double precision value to 0.0 SYNOPSIS c = IEEEDPTst( y ); d0 d0/d1 double y; long c; FUNCTION Compare y to 0.0, set the condition codes for less than, greater than, or equal to 0.0. Set the return value c to -1 if less than, to +1 if greater than, or 0 if equal to 0.0. INPUTS y -- IEEE double precision floating point value RESULT c = 1 cc = gt for (y > 0.0) c = 0 cc = eq for (y == 0.0) c = -1 cc = lt for (y < 0.0) BUGS SEE ALSO