github.com/matrixorigin/matrixone@v1.2.0/cgo/test/test_add.c (about)

     1  /* 
     2   * Copyright 2021 Matrix Origin
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *      http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  #include <stddef.h>
    18  #include <stdio.h>
    19  #include <limits.h>
    20  #include "../mo.h"
    21  
    22  int test_addi32() {
    23      int32_t r[8192];
    24      int32_t a[8192];
    25      int32_t b[8192];
    26      for (int i = 0; i < 8192; i++) {
    27          a[i] = i;
    28          b[i] = 1;
    29      }
    30  
    31      int32_t rc = SignedInt_VecAdd(r, a, b, 8192, NULL, 0, 4);
    32      return rc;
    33  }
    34  
    35  int test_adddec64() {
    36      int64_t r[8192];
    37      int64_t a[8192];
    38      int64_t b[8192];
    39      for (int i = 0; i < 8192; i++) {
    40          a[i] = -i;
    41          b[i] = i;
    42      }
    43  
    44      int32_t rc = Decimal64_VecAdd(r, a, b, 8192, NULL, 0);
    45      return rc;
    46  }
    47  
    48  
    49  int test_subdec64() {
    50      int64_t r[8192];
    51      int64_t a[8192];
    52      int64_t b[8192];
    53      for (int i = 0; i < 8192; i++) {
    54              a[i] = i;
    55              b[i] = i*3;
    56      }
    57      int32_t rc = Decimal64_VecSub(r, a, b, 8192, NULL, 0);
    58      return rc;
    59  }
    60  
    61  int test_divedec64(){
    62      int64_t r[10];
    63      int64_t a[10];
    64      int64_t b[10];
    65      for (int i = 0; i < 10; i++) {
    66          a[i] = (i+1)*1024;
    67          b[i] = 2;
    68      }
    69      int32_t rc = Decimal64_VecDiv(r, a, b, 10, NULL, 0);
    70  
    71      for (int i = 0; i < 10; i++) {
    72          printf("%ld / %ld = ", a[i], b[i]);
    73          printf("r[%d]=%ld \n", i, r[i]);
    74      }
    75  
    76      return rc;
    77  }
    78  
    79  int main() {
    80  //    test_addi32();
    81       //test_subdec64();
    82       //test_divedec64();
    83       test_adddec64();
    84       return 0;
    85  }