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!
file annotate diff log raw
nkeynes@1131
     1
#include <stdlib.h>
nkeynes@1131
     2
#include <stdio.h>
nkeynes@1131
     3
nkeynes@1169
     4
typedef unsigned char u8;
nkeynes@1169
     5
typedef signed char i8;
nkeynes@1169
     6
typedef unsigned short u16;
nkeynes@1169
     7
typedef signed short i16;
nkeynes@1169
     8
typedef unsigned int u32;
nkeynes@1169
     9
typedef signed int i32;
nkeynes@1169
    10
typedef unsigned long long u64;
nkeynes@1169
    11
typedef signed long long i64;
nkeynes@1131
    12
nkeynes@1131
    13
#define TEST_REPS 64
nkeynes@1131
    14
nkeynes@1169
    15
void printu8(u8 a) { printf( "%08X ", (unsigned int)a ); }
nkeynes@1169
    16
void printi8(i8 a) { printf( "%08X ", (unsigned int)(u8)a ); }
nkeynes@1169
    17
void printu16(u16 a) { printf( "%08X ", (unsigned int)a ); }
nkeynes@1169
    18
void printi16(i16 a) { printf( "%08X ", (unsigned int)(u16)a ); }
nkeynes@1169
    19
void printu32(u32 a) { printf( "%08X ", (unsigned int)a ); }
nkeynes@1169
    20
void printi32(i32 a) { printf( "%08X ", (unsigned int)a ); }
nkeynes@1169
    21
void printu64(u64 a) { printf( "%08X%08X ", (unsigned int)(a>>32),(unsigned int)a ); }
nkeynes@1169
    22
void printi64(i64 a) { printf( "%08X%08X ", (unsigned int)(a>>32),(unsigned int)a ); }
nkeynes@1131
    23
nkeynes@1131
    24
#define TEST_TYPE(T) \
nkeynes@1131
    25
void test##T() { \
nkeynes@1131
    26
    T a, b, c, d, e, f; \
nkeynes@1131
    27
    read(0,&a,sizeof(a)); read(0,&b,sizeof(b)); read(0,&c,sizeof(c)); read(0,&d,sizeof(d)); \
nkeynes@1131
    28
    e = a * b - c * d;\
nkeynes@1131
    29
    if( b != 0 && c != 0 ) { f = a / b + 1/c;  }\
nkeynes@1169
    30
    T g = e - f / 2  + (u32)b;\
nkeynes@1131
    31
    T h = b * c / d; T i = a / -d; \
nkeynes@1169
    32
    printf( "%d| ", (int)sizeof(a) ); \
nkeynes@1131
    33
    print##T(a); print##T(b); print##T(c); print##T(d); \
nkeynes@1131
    34
    printf( ": " ); print##T(e); print##T(f); print##T(g); \
nkeynes@1131
    35
    print##T(h); print##T(i); \
nkeynes@1131
    36
    printf( "\n" ); \
nkeynes@1131
    37
}
nkeynes@1131
    38
nkeynes@1169
    39
TEST_TYPE(u8);
nkeynes@1169
    40
TEST_TYPE(i8);
nkeynes@1169
    41
TEST_TYPE(u16);
nkeynes@1169
    42
TEST_TYPE(i16);
nkeynes@1169
    43
TEST_TYPE(u32);
nkeynes@1169
    44
TEST_TYPE(i32);
nkeynes@1169
    45
TEST_TYPE(u64);
nkeynes@1169
    46
TEST_TYPE(i64);
nkeynes@1131
    47
nkeynes@1131
    48
int main(int argc, char *argv[]) {
nkeynes@1131
    49
  unsigned i;
nkeynes@1131
    50
  
nkeynes@1169
    51
  for(i=0;i<TEST_REPS;i++ ) { testu64(); }
nkeynes@1169
    52
  for(i=0;i<TEST_REPS;i++ ) { testi64(); }
nkeynes@1169
    53
  for(i=0;i<TEST_REPS;i++ ) { testu32(); }
nkeynes@1169
    54
  for(i=0;i<TEST_REPS;i++ ) { testi32(); }
nkeynes@1169
    55
  for(i=0;i<TEST_REPS;i++ ) { testu16(); }
nkeynes@1169
    56
  for(i=0;i<TEST_REPS;i++ ) { testi16(); }
nkeynes@1169
    57
  for(i=0;i<TEST_REPS;i++ ) { testu8(); }
nkeynes@1169
    58
  for(i=0;i<TEST_REPS;i++ ) { testi8(); }
nkeynes@1131
    59
  return 0;
nkeynes@1131
    60
}
.