My Project
iFloat.h
Go to the documentation of this file.
1 #ifndef __IFLOAT_H__
2 #define __IFLOAT_H__
3 
4 /*
5  * iFloat.h - header for simple floating point functions.
6  *
7  * "Copyright (c) 2017 by Fritz Sieker."
8  *
9  * Permission to use, copy, modify, and distribute this software and its
10  * documentation for any purpose, without fee, and without written
11  * agreement is hereby granted, provided that the above copyright notice
12  * and the following two paragraphs appear in all copies of this software.
13  *
14  * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT,
15  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
16  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR
17  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
18  *
19  * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
22  * BASIS, AND THE AUTHOR NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
23  * UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
24  */
25 
53 #define HALF
54 #ifdef HALF
55 typedef short iFloat_t;
56 
57 #define BITS 16
58 #define BITS_EXP 5
59 #define BITS_MANT 10
60 #define EXP_BIAS 15
61 
62 #else
63 typedef int iFloat_t;
64 
65 #define BITS 32
66 #define BITS_EXP 8
67 #define BITS_MANT 23
68 #define EXP_BIAS 127
69 
70 #endif
71 
76 iFloat_t floatGetSign (iFloat_t x);
77 
82 iFloat_t floatGetExp (iFloat_t x);
83 
96 iFloat_t floatGetVal (iFloat_t x);
97 
104 void floatGetAll(iFloat_t x, iFloat_t* sign, iFloat_t*exp, iFloat_t* val);
105 
112 iFloat_t floatLeftMost1 (iFloat_t bits);
113 
119 iFloat_t floatAbs (iFloat_t x);
120 
129 iFloat_t floatNegate (iFloat_t x);
130 
137 iFloat_t floatAdd (iFloat_t x, iFloat_t y);
138 
145 iFloat_t floatSub (iFloat_t x, iFloat_t y);
146 
147 #endif
iFloat_t floatAbs(iFloat_t x)
Definition: iFloat.c:42
iFloat_t floatLeftMost1(iFloat_t bits)
Definition: iFloat.c:37
iFloat_t floatNegate(iFloat_t x)
Definition: iFloat.c:47
iFloat_t floatSub(iFloat_t x, iFloat_t y)
Definition: iFloat.c:59
void floatGetAll(iFloat_t x, iFloat_t *sign, iFloat_t *exp, iFloat_t *val)
Definition: iFloat.c:33
iFloat_t floatGetExp(iFloat_t x)
Definition: iFloat.c:23
iFloat_t floatGetSign(iFloat_t x)
Definition: iFloat.c:18
iFloat_t floatAdd(iFloat_t x, iFloat_t y)
Definition: iFloat.c:52
iFloat_t floatGetVal(iFloat_t x)
Definition: iFloat.c:28