Skip to content

Commit d59a376

Browse files
authored
Merge pull request #208 from Joe7M/master
Fix bug #149: Problem with big hex numbers in windows
2 parents 7475265 + 6fba7ff commit d59a376

File tree

7 files changed

+71
-9
lines changed

7 files changed

+71
-9
lines changed

samples/distro-examples/tests/matrices.bas

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,17 @@ m3rotate m, 2
6464
m3Apply m, strip
6565
if (strip != [[-18.23450585285103,14.19218649794793],[-10.96012643824558,17.52136119032507]]) then throw "m3Apply failed"
6666

67+
A = [1;2;3;4]
68+
B = transpose(A)
69+
if (B[0] != 1) then throw "Error TRANSPOSE()"
70+
if (B[1] != 2) then throw "Error TRANSPOSE()"
71+
if (B[2] != 3) then throw "Error TRANSPOSE()"
72+
if (B[3] != 4) then throw "Error TRANSPOSE()"
73+
A = [1,2; 3,4; 5,6]
74+
B = transpose(A)
75+
if (B[0,0] != 1) then throw "Error TRANSPOSE()"
76+
if (B[0,1] != 3) then throw "Error TRANSPOSE()"
77+
if (B[0,2] != 5) then throw "Error TRANSPOSE()"
78+
if (B[1,0] != 2) then throw "Error TRANSPOSE()"
79+
if (B[1,1] != 4) then throw "Error TRANSPOSE()"
80+
if (B[1,2] != 6) then throw "Error TRANSPOSE()"

src/common/blib_func.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2781,6 +2781,51 @@ void cmd_genfunc(long funcCode, var_t *r) {
27812781
mat_tov(r, m1, n, n, 1);
27822782
free(m1);
27832783
}
2784+
}
2785+
break;
2786+
//
2787+
// array <- TRANSPOSE(a)
2788+
//
2789+
case kwTRANSPOSE: {
2790+
int32_t rows, cols, pos1, pos2;
2791+
var_t *e;
2792+
2793+
v_init(r);
2794+
var_t *a = par_getvarray();
2795+
IF_ERR_RETURN;
2796+
2797+
if (v_maxdim(a) > 2) {
2798+
err_matdim();
2799+
IF_ERR_RETURN;
2800+
}
2801+
2802+
rows = ABS(v_lbound(a, 0) - v_ubound(a, 0)) + 1;
2803+
2804+
if (v_maxdim(a) == 2) {
2805+
cols = ABS(v_lbound(a, 1) - v_ubound(a, 1)) + 1;
2806+
} else {
2807+
cols = rows;
2808+
rows = 1;
2809+
}
2810+
2811+
var_num_t *m = (var_num_t *)malloc(((rows) * (cols)) * sizeof(var_num_t));
2812+
2813+
for (int32_t x = 0; x < cols; x++) {
2814+
for (int32_t y = 0; y < rows; y++) {
2815+
pos1 = y * cols + x;
2816+
pos2 = x * rows + y;
2817+
e = v_elem(a, pos1);
2818+
m[pos2] = v_getval(e);
2819+
}
2820+
}
2821+
2822+
if (cols > 1) {
2823+
mat_tov(r, m, cols, rows, 1);
2824+
} else {
2825+
mat_tov(r, m, rows, 1, 0);
2826+
}
2827+
2828+
free(m);
27842829
}
27852830
break;
27862831
//

src/common/eval.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,7 @@ static inline void eval_callf(var_t *r) {
12051205
case kwGAUSSJORDAN:
12061206
case kwFILES:
12071207
case kwINVERSE:
1208+
case kwTRANSPOSE:
12081209
case kwDETERM:
12091210
case kwJULIAN:
12101211
case kwDATEFMT:

src/common/kw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ enum func_keywords {
366366
kwGAUSSJORDAN,
367367
kwFILES,
368368
kwINVERSE,
369+
kwTRANSPOSE,
369370
kwDETERM,
370371
kwJULIAN,
371372
kwDATEFMT,

src/common/str.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,8 @@ var_int_t numexpr_strtol(char *source) {
555555
/**
556556
* convertion: binary to decimal
557557
*/
558-
long bintol(const char *str) {
559-
long r = 0;
558+
var_int_t bintol(const char *str) {
559+
var_int_t r = 0;
560560
char *p = (char *) str;
561561

562562
if (p == NULL) {
@@ -575,8 +575,8 @@ long bintol(const char *str) {
575575
/**
576576
* convertion: octal to decimal
577577
*/
578-
long octtol(const char *str) {
579-
long r = 0;
578+
var_int_t octtol(const char *str) {
579+
var_int_t r = 0;
580580
char *p = (char *) str;
581581

582582
if (p == NULL) {
@@ -595,8 +595,8 @@ long octtol(const char *str) {
595595
/**
596596
* convertion: hexadecimal to decimal
597597
*/
598-
long hextol(const char *str) {
599-
long r = 0;
598+
var_int_t hextol(const char *str) {
599+
var_int_t r = 0;
600600
char *p = (char *) str;
601601

602602
if (p == NULL) {

src/common/str.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ void str_alltrim(char *str);
170170
* @param str the string
171171
* @return the number
172172
*/
173-
long bintol(const char *str);
173+
var_int_t bintol(const char *str);
174174

175175
/**
176176
* @ingroup str
@@ -180,7 +180,7 @@ long bintol(const char *str);
180180
* @param str the string
181181
* @return the number
182182
*/
183-
long octtol(const char *str);
183+
var_int_t octtol(const char *str);
184184

185185
/**
186186
* @ingroup str
@@ -190,7 +190,7 @@ long octtol(const char *str);
190190
* @param str the string
191191
* @return the number
192192
*/
193-
long hextol(const char *str);
193+
var_int_t hextol(const char *str);
194194

195195
/**
196196
* @ingroup str

src/languages/keywords.en.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ struct func_keyword_s func_table[] = {
308308
{ "LINEQN", kwGAUSSJORDAN },
309309
{ "FILES", kwFILES },
310310
{ "INVERSE", kwINVERSE },
311+
{ "TRANSPOSE", kwTRANSPOSE },
311312
{ "DETERM", kwDETERM },
312313
{ "JULIAN", kwJULIAN },
313314
{ "DATEFMT", kwDATEFMT },

0 commit comments

Comments
 (0)