Home | History | Annotate | Download | only in src
      1 // Test floating point operations.
      2 
      3 void unaryOps() {
      4     // Unary ops
      5     printf("-%g = %g\n", 1.1, -1.1);
      6     printf("!%g = %d\n", 1.2, !1.2);
      7     printf("!%g = %d\n", 0.0, !0.0);
      8 }
      9 
     10 void binaryOps() {
     11     printf("double op double:\n");
     12     printf("%g + %g = %g\n", 1.0, 2.0, 1.0 + 2.0);
     13     printf("%g - %g = %g\n", 1.0, 2.0, 1.0 - 2.0);
     14     printf("%g * %g = %g\n", 1.0, 2.0, 1.0 * 2.0);
     15     printf("%g / %g = %g\n", 1.0, 2.0, 1.0 / 2.0);
     16 
     17     printf("float op float:\n");
     18     printf("%g + %g = %g\n", 1.0f, 2.0f, 1.0f + 2.0f);
     19     printf("%g - %g = %g\n", 1.0f, 2.0f, 1.0f - 2.0f);
     20     printf("%g * %g = %g\n", 1.0f, 2.0f, 1.0f * 2.0f);
     21     printf("%g / %g = %g\n", 1.0f, 2.0f, 1.0f / 2.0f);
     22 
     23     printf("double op float:\n");
     24     printf("%g + %g = %g\n", 1.0, 2.0f, 1.0 + 2.0f);
     25     printf("%g - %g = %g\n", 1.0, 2.0f, 1.0 - 2.0f);
     26     printf("%g * %g = %g\n", 1.0, 2.0f, 1.0 * 2.0f);
     27     printf("%g / %g = %g\n", 1.0, 2.0f, 1.0 / 2.0f);
     28 
     29     printf("double op int:\n");
     30     printf("%g + %d = %g\n", 1.0, 2, 1.0 + 2);
     31     printf("%g - %d = %g\n", 1.0, 2, 1.0 - 2);
     32     printf("%g * %d = %g\n", 1.0, 2, 1.0 * 2);
     33     printf("%g / %d = %g\n", 1.0, 2, 1.0 / 2);
     34 
     35     printf("int op double:\n");
     36     printf("%d + %g = %g\n", 1, 2.0, 1 + 2.0);
     37     printf("%d - %g = %g\n", 1, 2.0, 1 - 2.0);
     38     printf("%d * %g = %g\n", 1, 2.0, 1 * 2.0);
     39     printf("%d / %g = %g\n", 1, 2.0, 1 / 2.0);
     40 }
     41 
     42 void comparisonTestdd(double a, double b) {
     43     printf("%g op %g: < %d   <= %d   == %d   >= %d   > %d   != %d\n",
     44            a, b, a < b, a <= b, a == b, a >= b, a > b, a != b);
     45 }
     46 
     47 void comparisonOpsdd() {
     48     printf("double op double:\n");
     49     comparisonTestdd(1.0, 2.0);
     50     comparisonTestdd(1.0, 1.0);
     51     comparisonTestdd(2.0, 1.0);
     52 }
     53 
     54 
     55 void comparisonTestdf(double a, float b) {
     56     printf("%g op %g: < %d   <= %d   == %d   >= %d   > %d   != %d\n",
     57            a, b, a < b, a <= b, a == b, a >= b, a > b, a != b);
     58 }
     59 
     60 void comparisonOpsdf() {
     61     printf("double op float:\n");
     62     comparisonTestdf(1.0, 2.0f);
     63     comparisonTestdf(1.0, 1.0f);
     64     comparisonTestdf(2.0, 1.0f);
     65 }
     66 
     67 void comparisonTestff(float a, float b) {
     68     printf("%g op %g: < %d   <= %d   == %d   >= %d   > %d   != %d\n",
     69            a, b, a < b, a <= b, a == b, a >= b, a > b, a != b);
     70 }
     71 
     72 void comparisonOpsff() {
     73     printf("float op float:\n");
     74     comparisonTestff(1.0f, 2.0f);
     75     comparisonTestff(1.0f, 1.0f);
     76     comparisonTestff(2.0f, 1.0f);
     77 }
     78 
     79 void comparisonTestid(int a, double b) {
     80     printf("%d op %g: < %d   <= %d   == %d   >= %d   > %d   != %d\n",
     81            a, b, a < b, a <= b, a == b, a >= b, a > b, a != b);
     82 }
     83 
     84 void comparisonOpsid() {
     85     printf("int op double:\n");
     86     comparisonTestid(1, 2.0);
     87     comparisonTestid(1, 1.0);
     88     comparisonTestid(2, 1.0);
     89 }
     90 void comparisonTestdi(double a, int b) {
     91     printf("%g op %d: < %d   <= %d   == %d   >= %d   > %d   != %d\n",
     92            a, b, a < b, a <= b, a == b, a >= b, a > b, a != b);
     93 }
     94 
     95 void comparisonOpsdi() {
     96     printf("double op int:\n");
     97     comparisonTestdi(1.0f, 2);
     98     comparisonTestdi(1.0f, 1);
     99     comparisonTestdi(2.0f, 1);
    100 }
    101 
    102 void comparisonOps() {
    103     comparisonOpsdd();
    104     comparisonOpsdf();
    105     comparisonOpsff();
    106     comparisonOpsid();
    107     comparisonOpsdi();
    108 }
    109 
    110 int branch(double d) {
    111     if (d) {
    112         return 1;
    113     }
    114     return 0;
    115 }
    116 
    117 void testBranching() {
    118     printf("branching: %d %d %d\n", branch(-1.0), branch(0.0), branch(1.0));
    119 }
    120 
    121 void testpassi(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int l) {
    122     printf("testpassi: %d %d %d %d %d %d %d %d %d %d %d %d\n", a, b, c, d, e, f, g, h, i, j, k, l);
    123 }
    124 
    125 void testpassf(float a, float b, float c, float d, float e, float f, float g, float h, float i, float j, float k, float l) {
    126     printf("testpassf: %g %g %g %g %g %g %g %g %g %g %g %g\n", a, b, c, d, e, f, g, h, i, j, k, l);
    127 }
    128 
    129 void testpassd(double a, double b, double c, double d, double e, double f, double g, double h, double i, double j, double k, double l) {
    130     printf("testpassd: %g %g %g %g %g %g %g %g %g %g %g %g\n", a, b, c, d, e, f, g, h, i, j, k, l);
    131 }
    132 
    133 void testpassidf(int i, double d, float f) {
    134     printf("testpassidf: %d %g %g\n", i, d, f);
    135 }
    136 
    137 void testParameterPassing() {
    138     float x;
    139     testpassi(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
    140     testpassf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
    141     testpassd(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
    142     testpassi(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f);
    143     testpassf(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f);
    144     testpassd(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f);
    145     testpassi(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0);
    146     testpassf(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0);
    147     testpassd(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0);
    148     testpassidf(1, 2.0, 3.0f);
    149 }
    150 
    151 int main() {
    152     unaryOps();
    153     binaryOps();
    154     comparisonOps();
    155     testBranching();
    156     testParameterPassing();
    157     return 0;
    158 }
    159