]> git.sur5r.net Git - cc65/blob - src/common/fp.h
Removed (pretty inconsistently used) tab chars from source code base.
[cc65] / src / common / fp.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                   fp.h                                    */
4 /*                                                                           */
5 /*                          Floating point support                           */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2008      Ullrich von Bassewitz                                       */
10 /*               Roemerstrasse 52                                            */
11 /*               D-70794 Filderstadt                                         */
12 /* EMail:        uz@cc65.org                                                 */
13 /*                                                                           */
14 /*                                                                           */
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.                                    */
18 /*                                                                           */
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:                            */
22 /*                                                                           */
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              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
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.
43  *
44  * BEWARE: This code will currently only work on little endian systems!
45  *
46  */
47
48
49
50 #ifndef FP_H
51 #define FP_H
52
53
54
55 #include <stddef.h>
56
57
58
59 /*****************************************************************************/
60 /*                                   Data                                    */
61 /*****************************************************************************/
62
63
64 typedef union Float Float;
65 union Float {
66     float         V;
67 };
68
69
70
71 typedef union Double Double;
72 union Double {
73     double        V;
74 };
75
76
77
78 /*****************************************************************************/
79 /*                                   Code                                    */
80 /*****************************************************************************/
81
82
83
84 size_t FP_F_Size (void);
85 /* Return the size of the data type float */
86
87 unsigned char* FP_F_Data (Float Val);
88 /* Return the raw data of a float in a malloc'ed buffer. Free after use. */
89
90 Float FP_F_Make (float Val);
91 /* Make a floating point variable from a float value */
92
93 Float FP_F_FromInt (long Val);
94 /* Convert an integer into a floating point variable */
95
96 float FP_F_ToFloat (Float Val);
97 /* Convert a Float into a native float */
98
99 Float FP_F_Add (Float Left, Float Right);
100 /* Add two floats */
101
102 Float FP_F_Sub (Float Left, Float Right);
103 /* Subtract two floats */
104
105 Float FP_F_Mul (Float Left, Float Right);
106 /* Multiplicate two floats */
107
108 Float FP_F_Div (Float Left, Float Right);
109 /* Divide two floats */
110
111 size_t FP_D_Size (void);
112 /* Return the size of the data type double */
113
114 unsigned char* FP_D_Data (Double Val);
115 /* Return the raw data of a double in a malloc'ed buffer. Free after use. */
116
117 Double FP_D_Make (double Val);
118 /* Make a floating point variable from a float value */
119
120 Double FP_D_FromInt (long Val);
121 /* Convert an integer into a floating point variable */
122
123 double FP_D_ToFloat (Double Val);
124 /* Convert a Double into a native double */
125
126 Double FP_D_Add (Double Left, Double Right);
127 /* Add two floats */
128
129 Double FP_D_Sub (Double Left, Double Right);
130 /* Subtract two floats */
131
132 Double FP_D_Mul (Double Left, Double Right);
133 /* Multiplicate two floats */
134
135 Double FP_D_Div (Double Left, Double Right);
136 /* Divide two floats */
137
138
139
140 /* End of fp.h */
141
142 #endif
143
144
145
146
147