typed atomUnit

This commit is contained in:
dzaima 2021-09-10 19:53:35 +03:00
parent 732610fba1
commit fc67c92510
3 changed files with 12 additions and 6 deletions

View File

@ -168,7 +168,7 @@ B result = taga(r);
// see stuff.h for m_shArr/arr_shSetI/arr_shSetU for ways to batch-assign a single shape object to multiple objects
u32* rp; B r = m_c32arrv(%rp, 10); // 10-char string
// etc for m_(c32|f64|i32)arr[vcp]
// etc for m_(i8|i16|i32|c8|c16|c32|f64)arr[vcp]
usz ri=0; HArr_p r = m_harrs(123, &ri); // allocate 123-item arbitrary type array
// write items with r.a[ri++] or equivalent. Whenever GC could happen, ri must point to after the end of the currently set items

View File

@ -57,7 +57,7 @@ B acos_c1(B t, B x) { if (isF64(x)) return m_f64( acos(x.f)); P1( acos); thrM("
B atan_c1(B t, B x) { if (isF64(x)) return m_f64( atan(x.f)); P1( atan); thrM("•math.Atan: Argument contained non-number"); }
#undef P1
B lt_c1(B t, B x) { return m_unit(x); }
B lt_c1(B t, B x) { return m_atomUnit(x); }
B eq_c1(B t, B x) { B r = m_i32(isArr(x)? rnk(x) : 0); dec(x); return r; }
B ne_c1(B t, B x) { B r = m_f64(isArr(x)&&rnk(x)? *a(x)->sh : 1); dec(x); return r; }

View File

@ -84,14 +84,20 @@ static B m_unit(B x) {
static B m_atomUnit(B x) {
if (isNum(x)) {
Arr* r;
if (q_i32(x)) { i32* rp; r = m_i32arrp(&rp, 1); rp[0] = o2iu(x); }
else { f64* rp; r = m_f64arrp(&rp, 1); rp[0] = o2fu(x); }
i32 xi = (i32)x.f;
if (RARE(xi!=x.f)) { f64* rp; r = m_f64arrp(&rp, 1); rp[0] = x.f; }
else if (xi==(i8 )xi) { i8* rp; r = m_i8arrp (&rp, 1); rp[0] = xi; }
else if (xi==(i16)xi) { i16* rp; r = m_i16arrp(&rp, 1); rp[0] = xi; }
else { i32* rp; r = m_i32arrp(&rp, 1); rp[0] = xi; }
arr_shAlloc(r, 0);
return taga(r);
}
if (isC32(x)) {
u32* rp; Arr* r = m_c32arrp(&rp, 1);
rp[0] = o2cu(x);
Arr* r;
u32 xi = o2cu(x);
if (xi==(i8 )xi) { u8* rp; r = m_c8arrp (&rp, 1); rp[0] = xi; }
else if (xi==(i16)xi) { u16* rp; r = m_c16arrp(&rp, 1); rp[0] = xi; }
else { u32* rp; r = m_c32arrp(&rp, 1); rp[0] = xi; }
arr_shAlloc(r,0);
return taga(r);
}