cscpi (Core Functions)


Import

#include <archr/core/cscpi.h>
#include <archr/core/cscpi.hpp>
import archr.core
atomsLoads('archr')

Synopsis

 float archr_core_cscpi_1f32(const float i1);
(1)
 double archr_core_cscpi_1f64(const double i1);
(2)
 void archr_core_cscpi_f32(float *o0, const float *i1, size_t sz);
(3)
 void archr_core_cscpi_f64(double *o0, const double *i1, size_t sz);
(4)
 float cscpi(const float i1);
(1)
 double cscpi(const double i1);
(2)
 void cscpi(const float *i1, size_t sz, float *o0);
(3)
 void cscpi(const double *i1, size_t sz, double *o0);
(4)
template <typename Range> void cscpi(const Range& i1, Range& o0);
(5)
subroutine archr_core_cscpi_1f32(real(4) :: r, real(4), parameter :: i1)
(1)
subroutine archr_core_cscpi_1f64(real(8) :: r, real(8), parameter :: i1)
(2)
subroutine archr_core_cscpi_f32(real(4), dimension(*), parameter :: i1, integer(4) :: sz, real(4), dimension(*) :: o0)
(3)
subroutine archr_core_cscpi_f64(real(8), dimension(*), parameter :: i1, integer(4) :: sz, real(8), dimension(*) :: o0)
(4)
def cscpi(i1):
    return o0
(1)
function o0 = archr_core_cscpi(i1)
(1)

Description

Computes the Cosecant in multiple of PIs:

Parameters

i1_first, i1_last

The range of input elements

o0

The beginning of the destination range, may be equal to i1

i1

The scalar/contiguous data input element

Example


#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
#include <archr/core/cscpi.h>

double rand_in(double min, double max) {
  return min + ((double)(max - min) * ((double)rand() / RAND_MAX));
}

int main() {
  time_t t;
  size_t i;
  size_t sz = 10;
  float* i1 = (float*)malloc(sz * sizeof(float));
  float* o1 = (float*)malloc(sz * sizeof(float));

  srand((unsigned int)time(&t));
  for (i = 0; i < sz; ++i) {
    i1[i] = (float)rand_in((float)-10, (float)10);
  }
  archr_core_cscpi_f32(o1, i1, sz);
  for (i = 0; i < sz; ++i) {
    printf("%4lu: cscpi(%f) = %f\n", i, (double)i1[i], (double)o1[i]);
  }
}

Possible Output

   0: cscpi(-3.466457) = 1.005578
   1: cscpi(0.007624) = 41.756672
   2: cscpi(2.723485) = 1.309778
   3: cscpi(8.514454) = 1.001032
   4: cscpi(-6.434300) = -1.021686
   5: cscpi(-3.718313) = 1.292187
   6: cscpi(-7.909604) = 3.569066
   7: cscpi(-4.880131) = -2.719304
   8: cscpi(-8.887694) = -2.893986
   9: cscpi(-2.049582) = -6.445933

#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cstddef>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <archr/core/cscpi.hpp>

double rand_in(double min, double max) {
  return min + (double(max - min) * (double(std::rand()) / RAND_MAX));
}

int main() {
  std::size_t i;
  std::size_t sz = 10;
  std::vector<float> i1(sz);
  std::vector<float> o1(sz);

  std::srand(std::time(0));
  std::generate(i1.begin(), i1.end(), []() { return rand_in(float(-10), float(10)); });
  archr::core::cscpi(i1.data(), sz, o1.data());
  for (i = 0; i < sz; ++i) {
    std::cout << std::setw(4) << i << ": " << "cscpi" << "(" << i1[i] << ")" << " = " << o1[i] << std::endl;
  }
}

Possible Output

   0: cscpi(9.42286) = -1.0301
   1: cscpi(1.83788) = -2.05097
   2: cscpi(-3.26225) = 1.36278
   3: cscpi(-7.82217) = 1.8866
   4: cscpi(-5.00638) = 49.8945
   5: cscpi(-8.05106) = -6.26054
   6: cscpi(4.94578) = 5.89958
   7: cscpi(9.34714) = -1.12753
   8: cscpi(5.10651) = -3.04493
   9: cscpi(6.34508) = 1.13137

program main
  integer(4), parameter  :: sz = 10
  real(4), dimension(sz) :: o0
  real(4), dimension(sz) :: i0
  real(8)                :: r0, r1
  real(8)                :: min0, max0
  real(8)                :: min1, max1
  real(8)                :: min2, max2
  ! Init:
    min0 = -10
    max0 = 10
  do i=1,sz
    r0 = random_in(min0, max0)
    i0(i) = r0
  end do
  ! Example:
  call archr_core_cscpi_f32(o0, i0, size(i0))
  ! Output:
  do i=1,sz
    print *, i, ": ", o0(i)
  end do
contains
  ! Generate a random number within a range
  function random_in(mn, mx) result(r)
    real(8) :: r
    real(8), intent(in) :: mn, mx
    r = mn + (rand() * (mx - mn))
  end function random_in
end program

Possible Output

           1 :    2086.07568    
           2 :    1.09073627    
           3 :   -2.89896369    
           4 :   -1.93372357    
           5 :    1.13216484    
           6 :    1.07662654    
           7 :    5.41614580    
           8 :   -1.03022087    
           9 :   -1.03757429    
          10 :    1.21920168