Search
lxdream.org :: lxdream/test/randmath.c
lxdream 0.9.1
released Jun 29
Download Now
filename test/randmath.c
changeset 1169:23a9613aceb1
prev1131:4727c2006e0f
author Nathan Keynes <nkeynes@lxdream.org>
date Thu Apr 07 21:42:55 2011 +1000 (11 years ago)
permissions -rw-r--r--
last change Add german translation update from Riemann80, thanks!
view annotate diff log raw
     1 #include <stdlib.h>
     2 #include <stdio.h>
     4 typedef unsigned char u8;
     5 typedef signed char i8;
     6 typedef unsigned short u16;
     7 typedef signed short i16;
     8 typedef unsigned int u32;
     9 typedef signed int i32;
    10 typedef unsigned long long u64;
    11 typedef signed long long i64;
    13 #define TEST_REPS 64
    15 void printu8(u8 a) { printf( "%08X ", (unsigned int)a ); }
    16 void printi8(i8 a) { printf( "%08X ", (unsigned int)(u8)a ); }
    17 void printu16(u16 a) { printf( "%08X ", (unsigned int)a ); }
    18 void printi16(i16 a) { printf( "%08X ", (unsigned int)(u16)a ); }
    19 void printu32(u32 a) { printf( "%08X ", (unsigned int)a ); }
    20 void printi32(i32 a) { printf( "%08X ", (unsigned int)a ); }
    21 void printu64(u64 a) { printf( "%08X%08X ", (unsigned int)(a>>32),(unsigned int)a ); }
    22 void printi64(i64 a) { printf( "%08X%08X ", (unsigned int)(a>>32),(unsigned int)a ); }
    24 #define TEST_TYPE(T) \
    25 void test##T() { \
    26     T a, b, c, d, e, f; \
    27     read(0,&a,sizeof(a)); read(0,&b,sizeof(b)); read(0,&c,sizeof(c)); read(0,&d,sizeof(d)); \
    28     e = a * b - c * d;\
    29     if( b != 0 && c != 0 ) { f = a / b + 1/c;  }\
    30     T g = e - f / 2  + (u32)b;\
    31     T h = b * c / d; T i = a / -d; \
    32     printf( "%d| ", (int)sizeof(a) ); \
    33     print##T(a); print##T(b); print##T(c); print##T(d); \
    34     printf( ": " ); print##T(e); print##T(f); print##T(g); \
    35     print##T(h); print##T(i); \
    36     printf( "\n" ); \
    37 }
    39 TEST_TYPE(u8);
    40 TEST_TYPE(i8);
    41 TEST_TYPE(u16);
    42 TEST_TYPE(i16);
    43 TEST_TYPE(u32);
    44 TEST_TYPE(i32);
    45 TEST_TYPE(u64);
    46 TEST_TYPE(i64);
    48 int main(int argc, char *argv[]) {
    49   unsigned i;
    51   for(i=0;i<TEST_REPS;i++ ) { testu64(); }
    52   for(i=0;i<TEST_REPS;i++ ) { testi64(); }
    53   for(i=0;i<TEST_REPS;i++ ) { testu32(); }
    54   for(i=0;i<TEST_REPS;i++ ) { testi32(); }
    55   for(i=0;i<TEST_REPS;i++ ) { testu16(); }
    56   for(i=0;i<TEST_REPS;i++ ) { testi16(); }
    57   for(i=0;i<TEST_REPS;i++ ) { testu8(); }
    58   for(i=0;i<TEST_REPS;i++ ) { testi8(); }
    59   return 0;
    60 }
.