-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdfloat_free.c
More file actions
123 lines (103 loc) · 3.26 KB
/
dfloat_free.c
File metadata and controls
123 lines (103 loc) · 3.26 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/****************************************************
* libdfloat, version 0.2 Alpha *
* Description: Implements floating point numbers *
* with exact decimal representations *
* Author: Michael Warren, a.k.a. Psycho Cod3r *
* Date: October 2020 *
* License: Micheal Warren FSL Version 1.1 *
* Current module: Function versions that free the *
* source operand, making complex *
* expressions easier *
****************************************************/
#include <stdlib.h>
#include "dfloat.h"
// Note: Because these functions free their operands,
// you can't use the same variable multiple times in
// an expression that uses them. They should only be
// used for expressions that involve directly placing
// one function inside another function's operand list,
// which would make explicitly freeing the arguments
// impossible, thus necessitating a collection of
// functions that do that for you.
#define dfloatM_castNf( M, N )\
dfloat ## N ## _t *dfloat ## M ## _cast ## N ## f( dfloat ## M ## _t *src ){\
dfloat ## N ## _t *dst;\
dst = dfloat ## M ## _cast ## N ( src );\
free( src );\
return dst;\
}
dfloatM_castNf( 16, 32 )
dfloatM_castNf( 16, 64 )
dfloatM_castNf( 16, 128 )
dfloatM_castNf( 32, 16 )
dfloatM_castNf( 32, 64 )
dfloatM_castNf( 32, 128 )
dfloatM_castNf( 64, 16 )
dfloatM_castNf( 64, 32 )
dfloatM_castNf( 64, 128 )
dfloatM_castNf( 128, 16 )
dfloatM_castNf( 128, 32 )
dfloatM_castNf( 128, 64 )
#define dfloatN_addf( N )\
dfloat ## N ## _t *dfloat ## N ## _addf( dfloat ## N ## _t *arg1, dfloat ## N ## _t *arg2 ){\
dfloat ## N ## _add( arg1, arg2 );\
free( arg2 );\
return arg1;\
}
dfloatN_addf( 16 )
dfloatN_addf( 32 )
dfloatN_addf( 64 )
dfloatN_addf( 128 )
#define dfloatN_subf( N )\
dfloat ## N ## _t *dfloat ## N ## _subf( dfloat ## N ## _t *arg1, dfloat ## N ## _t *arg2 ){\
dfloat ## N ## _sub( arg1, arg2 );\
free( arg2 );\
return arg1;\
}
dfloatN_subf( 16 )
dfloatN_subf( 32 )
dfloatN_subf( 64 )
dfloatN_subf( 128 )
#define dfloatN_mulf( N )\
dfloat ## N ## _t *dfloat ## N ## _mulf( dfloat ## N ## _t *arg1, dfloat ## N ## _t *arg2 ){\
dfloat ## N ## _mul( arg1, arg2 );\
free( arg2 );\
return arg1;\
}
dfloatN_mulf( 16 )
dfloatN_mulf( 32 )
dfloatN_mulf( 64 )
dfloatN_mulf( 128 )
#define dfloatN_divf( N )\
dfloat ## N ## _t *dfloat ## N ## _divf( dfloat ## N ## _t *arg1, dfloat ## N ## _t *arg2, int precision ){\
dfloat ## N ## _div( arg1, arg2, precision );\
free( arg2 );\
return arg1;\
}
dfloatN_divf( 16 )
dfloatN_divf( 32 )
dfloatN_divf( 64 )
dfloatN_divf( 128 )
#define dfloatN_cmpf( N )\
int dfloat ## N ## _cmpf( dfloat ## N ## _t *arg1, dfloat ## N ## _t *arg2 ){\
int result;\
result = dfloat ## N ## _cmp( arg1, arg2 );\
free( arg1 );\
free( arg2 );\
return result;\
}
dfloatN_cmpf( 16 )
dfloatN_cmpf( 32 )
dfloatN_cmpf( 64 )
dfloatN_cmpf( 128 )
#define dfloatN_ftoaf( N )\
char *dfloat ## N ## _ftoaf( dfloat ## N ## _t *src ){\
char *dst;\
dst = dfloat ## N ## _ftoa( src );\
free( src );\
return dst;\
}
dfloatN_ftoaf( 16 )
dfloatN_ftoaf( 32 )
dfloatN_ftoaf( 64 )
dfloatN_ftoaf( 128 )