Initialize libbullet git in 2.0_beta.
[platform/upstream/libbullet.git] / Extras / simdmathlibrary / spu / tests / llroundd2.c
1 /* Test llroundd2 for SPU
2    Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
3    All rights reserved.
4
5    Redistribution and use in source and binary forms,
6    with or without modification, are permitted provided that the
7    following conditions are met:
8     * Redistributions of source code must retain the above copyright
9       notice, this list of conditions and the following disclaimer.
10     * Redistributions in binary form must reproduce the above copyright
11       notice, this list of conditions and the following disclaimer in the
12       documentation and/or other materials provided with the distribution.
13     * Neither the name of the Sony Computer Entertainment Inc nor the names
14       of its contributors may be used to endorse or promote products derived
15       from this software without specific prior written permission.
16
17    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27    POSSIBILITY OF SUCH DAMAGE.
28  */
29 /**
30  *
31  *@@ llroundd2 - rounds two doubles in to two nearest 64bit integer.
32  *
33  *@brief
34  * boundary test for llroundd2. 0.5 will be rounded to far from 0.
35  *
36  *@pre
37  *
38  *@criteria
39  * Run this program and check no error will be occurred.
40  *
41  *@note
42  *
43  **/
44
45
46 #include <stdio.h>
47 #include <stdlib.h>
48 #include <math.h>
49 #include <float.h>
50 #include "simdmath.h"
51 #include "common-test.h"
52 #include "testutils.h"
53
54
55 int main()
56 {
57         TEST_SET_START("20060916101000NM","NM", "llroundd2");
58
59 //   unsigned long long i11 = 0x7FFFFFFFFFFFFDFFull; //limit
60 //   unsigned long long i12 = 0xFFFFFFFFFFFFFDFFull; //limit
61
62 //   double x0  = hide_double(-HUGE_VAL);           // -Inf
63 //   double x1  = hide_double(HUGE_VAL);            // Inf
64    double x2  = hide_double(0.0);                  // +0
65    double x3  = hide_double(-0.0);                 // -0
66 //   double x4  = hide_double(nan(""));            // NaN -> NaN
67    double x5  = hide_double( 0.5);
68    double x6  = hide_double(-0.5);
69    double x7  = hide_double( 0.4999999999999999);  // 0
70    double x8  = hide_double(-0.4999999999999999);  // 0
71    double x9  = hide_double( 999999999999999.5);   // 1000000000000000
72    double x10 = hide_double(-999999999999999.5);   //-1000000000000000
73 //   double x11 = hide_double(make_double(i11));     // 9223372036854774784
74 //   double x12 = hide_double(make_double(i12));     //-9223372036854774784
75    double x11 = hide_double(9223372036854774784ll);     // 9223372036854774784
76    double x12 = hide_double(-9223372036854774784ll);     //-9223372036854774784
77    double x13 = DBL_MIN;
78    double x14 = (0.0 - DBL_MIN);
79
80         vec_double2 x0_v = ((vec_double2){x2, x3});    //+0,-0
81         vec_llong2  r0_v = ((vec_llong2){0,0});        // 0, 0
82         vec_double2 x1_v = ((vec_double2){x5, x8});    //+0.5,-0.4999999999999999
83         vec_llong2  r1_v = ((vec_llong2){1,0});        //   1, 0
84         vec_double2 x2_v = ((vec_double2){x7, x6});    //+0.4999999999999999, -0.5
85         vec_llong2  r2_v = ((vec_llong2){0,-1});       //                  0, -1
86         vec_double2 x3_v = ((vec_double2){x10, x11});  //-999999999999999.5, 9223372036854774784
87         vec_llong2  r3_v = ((vec_llong2){-1000000000000000ll,9223372036854774784ll});
88         vec_double2 x4_v = ((vec_double2){x12, x9});  //-9223372036854774784, 999999999999999.5
89         vec_llong2  r4_v = ((vec_llong2){-9223372036854774784ll,1000000000000000ll});
90         vec_double2 x5_v = ((vec_double2){x13, x14});
91         vec_llong2  r5_v = ((vec_llong2){0,0});
92         
93         vec_llong2  res_v;
94
95    TEST_START("llroundd2");
96    res_v = llroundd2 (x0_v);
97    TEST_CHECK("20060916101001NM", allequal_llong2( res_v, r0_v ), 0);
98    res_v = llroundd2 (x1_v);
99    TEST_CHECK("20060916101002NM", allequal_llong2( res_v, r1_v ), 0);
100    res_v = llroundd2 (x2_v);
101    TEST_CHECK("20060916101003NM", allequal_llong2( res_v, r2_v ), 0);
102    res_v = llroundd2 (x3_v);
103    TEST_CHECK("20060916101004NM", allequal_llong2( res_v, r3_v ), 0);
104    res_v = llroundd2 (x4_v);
105    TEST_CHECK("20060916101005NM", allequal_llong2( res_v, r4_v ), 0);
106    res_v = llroundd2 (x5_v);
107    TEST_CHECK("20060916101006NM", allequal_llong2( res_v, r5_v ), 0);
108
109    TEST_SET_DONE();
110
111    TEST_EXIT();
112
113 }