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!
59 /*****************************************************************************/
61 /*****************************************************************************/
64 typedef union Float Float;
71 typedef union Double Double;
78 /*****************************************************************************/
80 /*****************************************************************************/
84 size_t FP_F_Size (void);
85 /* Return the size of the data type float */
87 unsigned char* FP_F_Data (Float Val);
88 /* Return the raw data of a float in a malloc'ed buffer. Free after use. */
90 Float FP_F_Make (float Val);
91 /* Make a floating point variable from a float value */
93 Float FP_F_FromInt (long Val);
94 /* Convert an integer into a floating point variable */
96 float FP_F_ToFloat (Float Val);
97 /* Convert a Float into a native float */
99 Float FP_F_Add (Float Left, Float Right);
102 Float FP_F_Sub (Float Left, Float Right);
103 /* Subtract two floats */
105 Float FP_F_Mul (Float Left, Float Right);
106 /* Multiplicate two floats */
108 Float FP_F_Div (Float Left, Float Right);
109 /* Divide two floats */
111 size_t FP_D_Size (void);
112 /* Return the size of the data type double */
114 unsigned char* FP_D_Data (Double Val);
115 /* Return the raw data of a double in a malloc'ed buffer. Free after use. */
117 Double FP_D_Make (double Val);
118 /* Make a floating point variable from a float value */
120 Double FP_D_FromInt (long Val);
121 /* Convert an integer into a floating point variable */
123 double FP_D_ToFloat (Double Val);
124 /* Convert a Double into a native double */
126 Double FP_D_Add (Double Left, Double Right);
129 Double FP_D_Sub (Double Left, Double Right);
130 /* Subtract two floats */
132 Double FP_D_Mul (Double Left, Double Right);
133 /* Multiplicate two floats */
135 Double FP_D_Div (Double Left, Double Right);
136 /* Divide two floats */