101 lines
1.9 KiB
C
101 lines
1.9 KiB
C
#include <math.h>
|
|
#include <stdio.h>
|
|
#include <assert.h>
|
|
#include <limits.h>
|
|
#include <stdint.h>
|
|
#include "test.h"
|
|
|
|
uint64_t next();
|
|
void jump();
|
|
void long_jump();
|
|
|
|
int test_65() {
|
|
for (unsigned x = 0; ; x++) {
|
|
if (odd_ones(x) != __builtin_parity(x)) {
|
|
fprintf(stderr, "x = 0x%X\n", x);
|
|
return FAILED;
|
|
}
|
|
|
|
if (x == UINT_MAX) {
|
|
return PASSED;
|
|
}
|
|
}
|
|
}
|
|
|
|
int test_66() {
|
|
for (unsigned x = 0; ; x++) {
|
|
if ((x == 0 && leftmost_one(x) != 0) || (x != 0 && leftmost_one(x) != (1 << (31 - __builtin_clz(x))))) {
|
|
fprintf(stderr, "x = 0x%X\n", x);
|
|
return FAILED;
|
|
}
|
|
|
|
if (x == UINT_MAX) {
|
|
return PASSED;
|
|
}
|
|
}
|
|
}
|
|
|
|
int test_75(int test_cases) {
|
|
for (int i = 0; i < test_cases; i++) {
|
|
unsigned x = next(), y = next();
|
|
if ((uint64_t) x * y != ((uint64_t) unsigned_high_prod(x, y) << 32) + x * y) {
|
|
fprintf(stderr, "x = 0x%X, y = 0x%X\n", x, y);
|
|
return FAILED;
|
|
}
|
|
}
|
|
|
|
return PASSED;
|
|
}
|
|
|
|
int signed_high_prod(int x, int y) {
|
|
int64_t p = (int64_t) x * y;
|
|
return p >> (sizeof(int) << 3);
|
|
}
|
|
|
|
int test_80(int test_cases) {
|
|
for (int i = 0; i < test_cases; i++) {
|
|
int x = next();
|
|
if (threefourths(x) != (int64_t) x * 3 / 4) {
|
|
fprintf(stderr, "x = 0x%X\n", x);
|
|
return FAILED;
|
|
}
|
|
}
|
|
|
|
return PASSED;
|
|
}
|
|
|
|
float_bits f2b(float x) {
|
|
return *(float_bits*) &x;
|
|
}
|
|
|
|
float b2f(float_bits x) {
|
|
return *(float*) &x;
|
|
}
|
|
|
|
int test_95() {
|
|
for (float_bits x = 0; ; x++) {
|
|
float y = b2f(x) / 2, z = b2f(float_half(x));
|
|
if (y != z && !(isnan(y) && isnan(z))) {
|
|
fprintf(stderr, "%X %X\n", f2b(b2f(x) / 2), float_half(x));
|
|
fprintf(stderr, "f = 0x%X\n", x);
|
|
return FAILED;
|
|
}
|
|
|
|
if (x == UINT_MAX) {
|
|
return PASSED;
|
|
}
|
|
}
|
|
}
|
|
|
|
int test_97() {
|
|
for (int x = INT_MIN; ; x++) {
|
|
if (f2b((float) x) != float_i2f(x)) {
|
|
fprintf(stderr, "i = 0x%X\n", x);
|
|
return FAILED;
|
|
}
|
|
|
|
if (x == INT_MAX) {
|
|
return PASSED;
|
|
}
|
|
}
|
|
} |