update datalab

This commit is contained in:
18218461270@163.com 2025-07-31 21:58:10 +08:00
parent ee78c07528
commit 94c87bf33c

View File

@ -174,11 +174,11 @@ int isTmax(int x) {
* Rating: 2
*/
int allOddBits(int x) {
x = x & (x >> 16);
x = x & (x >> 8);
x = x & (x >> 4);
x = x & (x >> 2);
return (x >> 1) & 0x01;
x &= x >> 16;
x &= x >> 8;
x &= x >> 4;
x &= x >> 2;
return (x >> 1) & 1;
}
/*
* negate - return -x
@ -201,7 +201,7 @@ int negate(int x) {
* Rating: 3
*/
int isAsciiDigit(int x) {
x = x ^ 0x30;
x ^= 0x30;
return (!(x >> 4)) & ((~x >> 3) | ((~x >> 2) & (~x >> 1)));
}
/*
@ -212,8 +212,8 @@ int isAsciiDigit(int x) {
* Rating: 3
*/
int conditional(int x, int y, int z) {
x = !x - 1;
return (x & y) | (~x & z);
x = ~!x + 1;
return (~x & y) | (x & z);
}
/*
* isLessOrEqual - if x <= y then return 1, else return 0
@ -237,11 +237,11 @@ int isLessOrEqual(int x, int y) {
* Rating: 4
*/
int logicalNeg(int x) {
x = x | (x >> 16);
x = x | (x >> 8);
x = x | (x >> 4);
x = x | (x >> 2);
x = x | (x >> 1);
x |= x >> 16;
x |= x >> 8;
x |= x >> 4;
x |= x >> 2;
x |= x >> 1;
return ~x & 1;
}
/* howManyBits - return the minimum number of bits required to represent x in
@ -258,23 +258,23 @@ int logicalNeg(int x) {
*/
int howManyBits(int x) {
int cnt = 1, a;
x = x ^ (x >> 31);
x ^= x >> 31;
a = !!(x >> 16) << 4;
x = x >> a;
cnt = cnt + a;
x >>= a;
cnt += a;
a = !!(x >> 8) << 3;
x = x >> a;
cnt = cnt + a;
x >>= a;
cnt += a;
a = !!(x >> 4) << 2;
x = x >> a;
cnt = cnt + a;
x >>= a;
cnt += a;
a = !!(x >> 2) << 1;
x = x >> a;
cnt = cnt + a;
x >>= a;
cnt += a;
return cnt + !!x + !!(x >> 1);
}
@ -293,22 +293,22 @@ int howManyBits(int x) {
unsigned floatScale2(unsigned uf) {
unsigned s = uf & 0x80000000, f = uf & 0x007FFFFF, e = (uf >> 23) & 0xFF;
if (e == 0xFFU) {
if (e == 0xFF) {
return uf;
}
if (e == 0U) {
if (f == 0U) {
if (e == 0) {
if (f == 0) {
return uf;
} else {
e = (f >= 0x00400000U);
f = (f << 1) & 0x007FFFFFU;
e = f >= 0x00400000;
f = (f << 1) & 0x007FFFFF;
return s | (e << 23) | f;
}
}
e = e + 1;
if (e == 0xFFU) {
e++;
if (e == 0xFF) {
f = 0;
}
return s | (e << 23) | f;
@ -328,11 +328,11 @@ unsigned floatScale2(unsigned uf) {
int floatFloat2Int(unsigned uf) {
unsigned s = uf & 0x80000000, f = uf & 0x007FFFFF, e = (uf >> 23) & 0xFF;
if (e == 0xFFU) {
return 0x80000000U;
if (e == 0xFF) {
return 0x80000000;
}
if (e == 0U) {
if (e == 0) {
return 0;
} else {
int E = e - 127;
@ -340,15 +340,15 @@ int floatFloat2Int(unsigned uf) {
if (E <= -1) {
return 0;
} else if (E <= 30) {
f = (f | 0x00800000);
f |= 0x00800000;
if (E >= 23) {
f = f << (E - 23);
f <<= E - 23;
} else {
f = f >> (23 - E);
f >>= 23 - E;
}
return s ? -f : f;
} else {
return 0x80000000U;
return 0x80000000;
}
}
}
@ -367,12 +367,12 @@ int floatFloat2Int(unsigned uf) {
*/
unsigned floatPower2(int x) {
if (x < -149) {
return 0U;
return 0;
} else if (x <= -127) {
return 1U << (x + 149);
return 1 << (x + 149);
} else if (x <= 127) {
return (x + 127) << 23;
} else {
return 0x7F800000U;
return 0x7F800000;
}
}