1 /*****************************************************************************/
5 /* Floating point support */
9 /* (C) 2008 Ullrich von Bassewitz */
10 /* Roemerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
36 /* The compiler must use the same floating point arithmetic as the target
37 ** platform, otherwise expressions will yield a different result when
38 ** evaluated in the compiler or on the target platform. Since writing a target
39 ** and source library is almost double the work, we will at least add the
40 ** hooks here, and define functions for a plug in library that may be added
41 ** at a later time. Currently we use the builtin data types of the compiler
42 ** that translates cc65.
44 ** BEWARE: This code will currently only work on little endian systems!
58 /*****************************************************************************/
60 /*****************************************************************************/
63 typedef union Float Float;
70 typedef union Double Double;
77 /*****************************************************************************/
79 /*****************************************************************************/
83 size_t FP_F_Size (void);
84 /* Return the size of the data type float */
86 unsigned char* FP_F_Data (Float Val);
87 /* Return the raw data of a float in a malloc'ed buffer. Free after use. */
89 Float FP_F_Make (float Val);
90 /* Make a floating point variable from a float value */
92 Float FP_F_FromInt (long Val);
93 /* Convert an integer into a floating point variable */
95 float FP_F_ToFloat (Float Val);
96 /* Convert a Float into a native float */
98 Float FP_F_Add (Float Left, Float Right);
101 Float FP_F_Sub (Float Left, Float Right);
102 /* Subtract two floats */
104 Float FP_F_Mul (Float Left, Float Right);
105 /* Multiplicate two floats */
107 Float FP_F_Div (Float Left, Float Right);
108 /* Divide two floats */
110 size_t FP_D_Size (void);
111 /* Return the size of the data type double */
113 unsigned char* FP_D_Data (Double Val);
114 /* Return the raw data of a double in a malloc'ed buffer. Free after use. */
116 Double FP_D_Make (double Val);
117 /* Make a floating point variable from a float value */
119 Double FP_D_FromInt (long Val);
120 /* Convert an integer into a floating point variable */
122 double FP_D_ToFloat (Double Val);
123 /* Convert a Double into a native double */
125 Double FP_D_Add (Double Left, Double Right);
128 Double FP_D_Sub (Double Left, Double Right);
129 /* Subtract two floats */
131 Double FP_D_Mul (Double Left, Double Right);
132 /* Multiplicate two floats */
134 Double FP_D_Div (Double Left, Double Right);
135 /* Divide two floats */