-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfloat_arith.h
More file actions
59 lines (51 loc) · 1.73 KB
/
Copy pathfloat_arith.h
File metadata and controls
59 lines (51 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*******************************************************************************
* Copyright (c) 2012, 2014 Etienne Dublé, CNRS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or see the LICENSE file joined with this program.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
#ifndef __FLOAT_ARITH_H
#define __FLOAT_ARITH_H
#include <stdint.h>
#define INT_SIZE 16
#if INT_SIZE == 32
#define S_INT int16_t
#define INT int32_t
#define L_INT int64_t
#else
#if INT_SIZE == 16
#define S_INT int8_t
#define INT int16_t
#define L_INT int32_t
#endif
#endif
typedef struct st_float {
INT int_value;
S_INT shifts;
} FLOAT;
#define ABS(f) (((f)>0)?(f):-(f))
void copy(FLOAT *a, FLOAT *b);
void multiply(FLOAT *a, FLOAT *b, FLOAT *result);
void multiply_by_int(FLOAT *a, INT i, FLOAT *result);
void divide(FLOAT *a, FLOAT *b, FLOAT *result);
void divide_by_int(FLOAT *a, INT i, FLOAT *result);
void add(FLOAT *a, FLOAT *b, FLOAT *result);
void negate(FLOAT *a, FLOAT *result);
void substract(FLOAT *a, FLOAT *b, FLOAT *result);
short is_greater(FLOAT *a, FLOAT *b);
void ln(FLOAT *f, FLOAT *result);
INT int_value(FLOAT *f);
void copy_int_to_float(INT i, FLOAT *result);
void print_float(FLOAT *f, S_INT dec_num);
#endif