-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.cpp
More file actions
241 lines (214 loc) · 4.37 KB
/
extension.cpp
File metadata and controls
241 lines (214 loc) · 4.37 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#include "pxt.h"
#include "simulate_float.h"
namespace sfloat {
/**
* Perform soft-float conversion
*/
//% blockId=sfloat_fromInt block="Convert to SoftFloat %x"
int fromInt(int x) {
return int_to_sfloat(x);
}
/**
* Add two soft floats
*/
//% blockId=sfloat_add block="[SF] add x %x|and y %y"
int add(int x, int y)
{
return sfloat_add(x, y);
}
/**
* Multiply two soft floats
*/
//% blockId=sfloat_add_f block="[F] add x %x|and y %y"
int add_f(int x, int y)
{
float c = *((float*)(&x)) + *((float*)(&y));
return *((int *)(&c));
}
/**
* Multiply two soft floats
*/
//% blockId=sfloat_multiply block="[SF] multiply x %x|and y %y"
int multiply(int x, int y)
{
return sfloat_multiply(x, y);
}
/**
* Multiply two soft floats
*/
//% blockId=sfloat_multiply_f block="[F] multiply x %x|and y %y"
int multiply_f(int x, int y)
{
float c = *((float*)(&x)) * *((float*)(&y));
return *((int *)(&c));
}
/**
* Subtract two soft floats
*/
//% blockId=sfloat_minus block="[SF] subtract y %y|from x %x"
int minus(int x, int y)
{
return sfloat_minus(x, y);
}
/**
* Subtract two soft floats
*/
//% blockId=sfloat_minus_f block="[F] subtract y %y|from x %x"
int minus_f(int x, int y)
{
float c = *((float*)(&x)) - *((float*)(&y));
return *((int *)(&c));
}
/**
* Divide two soft floats
*/
//% blockId=sfloat_div_f block="[F] divide x %x|by y %y"
int div_f(int x, int y)
{
float c = (*((float *)&x)) / (*((float *)&y));
return *((int *)(&c));
}
/**
* Divide two soft floats
*/
//% blockId=sfloat_div block="[SF] divide x %x|by y %y"
int div(int x, int y)
{
return sfloat_divide(x,y);
}
/**
* Get sine of a soft float
*/
//% blockId=sfloat_sin block="[SF] sine of radians %x"
int sin(int x)
{
return sfloat_sin(x);
}
/**
* Get sine of a soft float
*/
//% blockId=sfloat_sin_f block="[F] sine of radians %x"
int sin_f(int x)
{
float c = sin(*((float *)&x));
return *((int *)(&c));
}
/**
* Get cosine of a soft float
*/
//% blockId=sfloat_cos block="[SF] cosine of radians %x"
int cos(int x)
{
return sfloat_cos(x);
}
/**
* Get cosine of a soft float
*/
//% blockId=sfloat_cos_f block="[F] cosine of radians %x"
int cos_f(int x)
{
float c = cos(*((float *)&x));
return *((int *)(&c));
}
/**
* Get tangens of a soft float
*/
//% blockId=sfloat_tan block="[SF] tangens of radians %x"
int tan(int x)
{
return sfloat_tan(x);
}
/**
* Get tangens of a soft float
*/
//% blockId=sfloat_tan_f block="[F] tangens of radians %x"
int tan_f(int x)
{
float c = tan(*((float *)&x));
return *((int *)(&c));
}
/**
* Get square root of a soft float
*/
//% blockId=sfloat_sqrt block="[SF] sqrt of x %x"
int sqrt(int x)
{
return sfloat_sqrt(x);
}
/**
* Get square root of a soft float
*/
//% blockId=sfloat_sqrt_f block="[F] sqrt of x %x"
int sqrt_f(int x)
{
float c = sqrt(*((float *)&x));
return *((int *)(&c));
}
/**
* Get arcus sine of a soft float
*/
//% blockId=sfloat_asin block="[SF] arcsin of x %x"
int asin(int x)
{
return sfloat_asin(x);
}
/**
* Get arcus sine of a soft float
*/
//% blockId=sfloat_asin_f block="[F] arcsin of x %x"
int asin_f(int x)
{
float c = asin(*((float *)&x));
return *((int *)(&c));
}
/**
* Get arcus cosine of a soft float
*/
//% blockId=sfloat_acos block="[SF] arccos of x %x"
int acos(int x)
{
return sfloat_acos(x);
}
/**
* Get arcus cosine of a soft float
*/
//% blockId=sfloat_acos_f block="[F] arccos of x %x"
int acos_f(int x)
{
float c = acos(*((float *)&x));
return *((int *)(&c));
}
/**
* Get arcus tangens of a soft float
*/
//% blockId=sfloat_atan block="[SF] arctan of x %x"
int atan(int x)
{
return sfloat_atan(x);
}
/**
* Get arcus tangens of a soft float
*/
//% blockId=sfloat_atan_f block="[F] arctan of x %x"
int atan_f(int x)
{
float c = atan(*((float *)&x));
return *((int *)(&c));
}
/**
* Get arcus tangens 2 of two soft float
*/
//% blockId=sfloat_atan2 block="[SF] atan2 of y %y|and x %x"
int atan2(int y, int x)
{
return sfloat_atan2(y, x);
}
/**
* Get opposite of a soft float
*/
//% blockId=sfloat_neg block="[SF] opposite of x %x"
int neg(int x)
{
return (x ^ (1 << 31));
}
}