Skip to content

Commit 140f0d9

Browse files
committed
Fixed extension and updated shim
1 parent 558d53b commit 140f0d9

File tree

2 files changed

+94
-34
lines changed

2 files changed

+94
-34
lines changed

extension.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ namespace sfloat {
2525
* Multiply two soft floats
2626
*/
2727
//% blockId=sfloat_add_f block="[F] add x %x|and y %y"
28-
int multiply(int x, int y)
28+
int add_f(int x, int y)
2929
{
30-
float c = ((float*)(&x)) + ((float*)(&y));
30+
float c = *((float*)(&x)) + *((float*)(&y));
3131
return *((int *)(&c));
3232
}
3333

@@ -44,9 +44,9 @@ namespace sfloat {
4444
* Multiply two soft floats
4545
*/
4646
//% blockId=sfloat_multiply_f block="[F] multiply x %x|and y %y"
47-
int multiply(int x, int y)
47+
int multiply_f(int x, int y)
4848
{
49-
float c = ((float*)(&x)) * ((float*)(&y));
49+
float c = *((float*)(&x)) * *((float*)(&y));
5050
return *((int *)(&c));
5151
}
5252

@@ -63,17 +63,17 @@ namespace sfloat {
6363
* Subtract two soft floats
6464
*/
6565
//% blockId=sfloat_minus_f block="[F] subtract y %y|from x %x"
66-
int multiply(int x, int y)
66+
int minus_f(int x, int y)
6767
{
68-
float c = ((float*)(&x)) - ((float*)(&y));
68+
float c = *((float*)(&x)) - *((float*)(&y));
6969
return *((int *)(&c));
7070
}
7171

7272
/**
7373
* Divide two soft floats
7474
*/
7575
//% blockId=sfloat_div_f block="[F] divide x %x|by y %y"
76-
int div_float(int x, int y)
76+
int div_f(int x, int y)
7777
{
7878
float c = (*((float *)&x)) / (*((float *)&y));
7979
return *((int *)(&c));
@@ -101,7 +101,7 @@ namespace sfloat {
101101
* Get sine of a soft float
102102
*/
103103
//% blockId=sfloat_sin_f block="[F] sine of radians %x"
104-
int sin(int x)
104+
int sin_f(int x)
105105
{
106106
float c = sin(*((float *)&x));
107107
return *((int *)(&c));
@@ -120,7 +120,7 @@ namespace sfloat {
120120
* Get cosine of a soft float
121121
*/
122122
//% blockId=sfloat_cos_f block="[F] cosine of radians %x"
123-
int sin(int x)
123+
int cos_f(int x)
124124
{
125125
float c = cos(*((float *)&x));
126126
return *((int *)(&c));
@@ -139,7 +139,7 @@ namespace sfloat {
139139
* Get tangens of a soft float
140140
*/
141141
//% blockId=sfloat_tan_f block="[F] tangens of radians %x"
142-
int tan(int x)
142+
int tan_f(int x)
143143
{
144144
float c = tan(*((float *)&x));
145145
return *((int *)(&c));
@@ -158,9 +158,9 @@ namespace sfloat {
158158
* Get square root of a soft float
159159
*/
160160
//% blockId=sfloat_sqrt_f block="[F] sqrt of x %x"
161-
int sqrt(int x)
161+
int sqrt_f(int x)
162162
{
163-
rfloat c = sqrt(*((float *)&x));
163+
float c = sqrt(*((float *)&x));
164164
return *((int *)(&c));
165165
}
166166

@@ -177,9 +177,9 @@ namespace sfloat {
177177
* Get arcus sine of a soft float
178178
*/
179179
//% blockId=sfloat_asin_f block="[F] arcsin of x %x"
180-
int asin(int x)
180+
int asin_f(int x)
181181
{
182-
rfloat c = asin(*((float *)&x));
182+
float c = asin(*((float *)&x));
183183
return *((int *)(&c));
184184
}
185185

@@ -196,9 +196,9 @@ namespace sfloat {
196196
* Get arcus cosine of a soft float
197197
*/
198198
//% blockId=sfloat_acos_f block="[F] arccos of x %x"
199-
int acos(int x)
199+
int acos_f(int x)
200200
{
201-
rfloat c = acos(*((float *)&x));
201+
float c = acos(*((float *)&x));
202202
return *((int *)(&c));
203203
}
204204

@@ -215,9 +215,9 @@ namespace sfloat {
215215
* Get arcus tangens of a soft float
216216
*/
217217
//% blockId=sfloat_atan_f block="[F] arctan of x %x"
218-
int atan(int x)
218+
int atan_f(int x)
219219
{
220-
rfloat c = atan(*((float *)&x));
220+
float c = atan(*((float *)&x));
221221
return *((int *)(&c));
222222
}
223223

shims.d.ts

Lines changed: 76 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,85 +10,145 @@ declare namespace sfloat {
1010
/**
1111
* Add two soft floats
1212
*/
13-
//% blockId=sfloat_add block="Add two SoftFloats x %x|and y %y" shim=sfloat::add
13+
//% blockId=sfloat_add block="[SF] add x %x|and y %y" shim=sfloat::add
1414
function add(x: number, y: number): number;
1515

1616
/**
1717
* Multiply two soft floats
1818
*/
19-
//% blockId=sfloat_multiply block="Multiply x %x|and y %y" shim=sfloat::multiply
19+
//% blockId=sfloat_add_f block="[F] add x %x|and y %y" shim=sfloat::add_f
20+
function add_f(x: number, y: number): number;
21+
22+
/**
23+
* Multiply two soft floats
24+
*/
25+
//% blockId=sfloat_multiply block="[SF] multiply x %x|and y %y" shim=sfloat::multiply
2026
function multiply(x: number, y: number): number;
2127

28+
/**
29+
* Multiply two soft floats
30+
*/
31+
//% blockId=sfloat_multiply_f block="[F] multiply x %x|and y %y" shim=sfloat::multiply_f
32+
function multiply_f(x: number, y: number): number;
33+
2234
/**
2335
* Subtract two soft floats
2436
*/
25-
//% blockId=sfloat_minus block="subtract x %x|from y %y" shim=sfloat::minus
37+
//% blockId=sfloat_minus block="[SF] subtract y %y|from x %x" shim=sfloat::minus
2638
function minus(x: number, y: number): number;
2739

2840
/**
29-
* Divide two integers
41+
* Subtract two soft floats
3042
*/
31-
//% blockId=sfloat_div_float block="divide x %x|by y %y (using floats)" shim=sfloat::div_float
32-
function div_float(x: number, y: number): number;
43+
//% blockId=sfloat_minus_f block="[F] subtract y %y|from x %x" shim=sfloat::minus_f
44+
function minus_f(x: number, y: number): number;
3345

3446
/**
3547
* Divide two soft floats
3648
*/
37-
//% blockId=sfloat_div block="divide x %x|by y %y" shim=sfloat::div
49+
//% blockId=sfloat_div_f block="[F] divide x %x|by y %y" shim=sfloat::div_f
50+
function div_f(x: number, y: number): number;
51+
52+
/**
53+
* Divide two soft floats
54+
*/
55+
//% blockId=sfloat_div block="[SF] divide x %x|by y %y" shim=sfloat::div
3856
function div(x: number, y: number): number;
3957

4058
/**
4159
* Get sine of a soft float
4260
*/
43-
//% blockId=sfloat_sin block="sine of radians %x" shim=sfloat::sin
61+
//% blockId=sfloat_sin block="[SF] sine of radians %x" shim=sfloat::sin
4462
function sin(x: number): number;
4563

64+
/**
65+
* Get sine of a soft float
66+
*/
67+
//% blockId=sfloat_sin_f block="[F] sine of radians %x" shim=sfloat::sin_f
68+
function sin_f(x: number): number;
69+
4670
/**
4771
* Get cosine of a soft float
4872
*/
49-
//% blockId=sfloat_cos block="cosine of radians %x" shim=sfloat::cos
73+
//% blockId=sfloat_cos block="[SF] cosine of radians %x" shim=sfloat::cos
5074
function cos(x: number): number;
5175

76+
/**
77+
* Get cosine of a soft float
78+
*/
79+
//% blockId=sfloat_cos_f block="[F] cosine of radians %x" shim=sfloat::cos_f
80+
function cos_f(x: number): number;
81+
5282
/**
5383
* Get tangens of a soft float
5484
*/
55-
//% blockId=sfloat_sin block="tangens of radians %x" shim=sfloat::tan
85+
//% blockId=sfloat_tan block="[SF] tangens of radians %x" shim=sfloat::tan
5686
function tan(x: number): number;
5787

88+
/**
89+
* Get tangens of a soft float
90+
*/
91+
//% blockId=sfloat_tan_f block="[F] tangens of radians %x" shim=sfloat::tan_f
92+
function tan_f(x: number): number;
93+
5894
/**
5995
* Get square root of a soft float
6096
*/
61-
//% blockId=sfloat_sin block="sqrt of x %x" shim=sfloat::sqrt
97+
//% blockId=sfloat_sqrt block="[SF] sqrt of x %x" shim=sfloat::sqrt
6298
function sqrt(x: number): number;
6399

100+
/**
101+
* Get square root of a soft float
102+
*/
103+
//% blockId=sfloat_sqrt_f block="[F] sqrt of x %x" shim=sfloat::sqrt_f
104+
function sqrt_f(x: number): number;
105+
64106
/**
65107
* Get arcus sine of a soft float
66108
*/
67-
//% blockId=sfloat_sin block="arcsin of x %x" shim=sfloat::asin
109+
//% blockId=sfloat_asin block="[SF] arcsin of x %x" shim=sfloat::asin
68110
function asin(x: number): number;
69111

112+
/**
113+
* Get arcus sine of a soft float
114+
*/
115+
//% blockId=sfloat_asin_f block="[F] arcsin of x %x" shim=sfloat::asin_f
116+
function asin_f(x: number): number;
117+
70118
/**
71119
* Get arcus cosine of a soft float
72120
*/
73-
//% blockId=sfloat_sin block="arccos of x %x" shim=sfloat::acos
121+
//% blockId=sfloat_acos block="[SF] arccos of x %x" shim=sfloat::acos
74122
function acos(x: number): number;
75123

124+
/**
125+
* Get arcus cosine of a soft float
126+
*/
127+
//% blockId=sfloat_acos_f block="[F] arccos of x %x" shim=sfloat::acos_f
128+
function acos_f(x: number): number;
129+
76130
/**
77131
* Get arcus tangens of a soft float
78132
*/
79-
//% blockId=sfloat_atan block="arctan of x %x" shim=sfloat::atan
133+
//% blockId=sfloat_atan block="[SF] arctan of x %x" shim=sfloat::atan
80134
function atan(x: number): number;
81135

136+
/**
137+
* Get arcus tangens of a soft float
138+
*/
139+
//% blockId=sfloat_atan_f block="[F] arctan of x %x" shim=sfloat::atan_f
140+
function atan_f(x: number): number;
141+
82142
/**
83143
* Get arcus tangens 2 of two soft float
84144
*/
85-
//% blockId=sfloat_atan2 block="atan2 of y %y|and x %x" shim=sfloat::atan2
145+
//% blockId=sfloat_atan2 block="[SF] atan2 of y %y|and x %x" shim=sfloat::atan2
86146
function atan2(y: number, x: number): number;
87147

88148
/**
89149
* Get opposite of a soft float
90150
*/
91-
//% blockId=sfloat_neg block="opposite of x %x" shim=sfloat::neg
151+
//% blockId=sfloat_neg block="[SF] opposite of x %x" shim=sfloat::neg
92152
function neg(x: number): number;
93153
}
94154

0 commit comments

Comments
 (0)