pow2 (Core Functions)


Import

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

Synopsis

 float archr_core_pow2_1f32f32(const float i1, const float i2);
(1)
 double archr_core_pow2_1f64f64(const double i1, const double i2);
(2)
 void archr_core_pow2_f32f32(float *o0, const float *i1, size_t sz, const float *i2);
(3)
 void archr_core_pow2_f64f64(double *o0, const double *i1, size_t sz, const double *i2);
(4)
 float pow2(const float i1, const float i2);
(1)
 double pow2(const double i1, const double i2);
(2)
 void pow2(const float *i1, size_t sz, const float *i2, float *o0);
(3)
 void pow2(const double *i1, size_t sz, const double *i2, double *o0);
(4)
template <typename Range> void pow2(const Range& i1, const Range& i2, Range& o0);
(5)
subroutine archr_core_pow2_1f32f32(real(4) :: r, real(4), parameter :: i1, real(4), parameter :: i2)
(1)
subroutine archr_core_pow2_1f64f64(real(8) :: r, real(8), parameter :: i1, real(8), parameter :: i2)
(2)
subroutine archr_core_pow2_f32f32(real(4), dimension(*), parameter :: i1, integer(4) :: sz, real(4), dimension(*), parameter :: i2, real(4), dimension(*) :: o0)
(3)
subroutine archr_core_pow2_f64f64(real(8), dimension(*), parameter :: i1, integer(4) :: sz, real(8), dimension(*), parameter :: i2, real(8), dimension(*) :: o0)
(4)
def pow2(i1, i2):
    return o0
(1)
function o0 = archr_core_pow2(i1, i2)
(1)

Description

Computes the pow2:

Parameters

i1_first, i1_last

The first range of input elements

i2

The beggining of the the second range of input elements

o0

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

i1, i2

The scalar/contiguous data input elements

Example


#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
#include <archr/core/pow2.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* i2 = (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);
  i2[i] = (float)rand_in((float)-10, (float)10);
  }
  archr_core_pow2_f32f32(o1, i1, sz, i2);
  for (i = 0; i < sz; ++i) {
    printf("%4lu: pow2(%f, %f) = %f\n", i, (double)i1[i], (double)i2[i], (double)o1[i]);
  }
}

Possible Output

   0: pow2(-3.466457, 0.007624) = -3.466457
   1: pow2(2.723485, 8.514454) = 697.212158
   2: pow2(-6.434300, -3.718313) = -0.804287
   3: pow2(-7.909604, -4.880131) = -0.494350
   4: pow2(-8.887694, -2.049582) = -2.221924
   5: pow2(9.701183, -3.220847) = 1.212648
   6: pow2(-0.194786, -8.646268) = -0.000761
   7: pow2(6.732231, -0.829226) = 6.732231
   8: pow2(0.405202, -4.682662) = 0.025325
   9: pow2(2.318254, 2.594378) = 9.273018

#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cstddef>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <archr/core/pow2.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> i2(sz);
  std::vector<float> o1(sz);

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

Possible Output

   0: pow2(9.42286, -0.338315) = 9.42286
   1: pow2(1.83788, -6.32984) = 0.0287169
   2: pow2(-3.26225, 1.88199) = -6.52451
   3: pow2(-7.82217, 0.493357) = -7.82217
   4: pow2(-5.00638, -2.94046) = -1.2516
   5: pow2(-8.05106, -9.90081) = -0.0157247
   6: pow2(4.94578, -3.02308) = 0.618223
   7: pow2(9.34714, -9.77158) = 0.0182561
   8: pow2(5.10651, 8.59657) = 1307.27
   9: pow2(6.34508, 9.59417) = 3248.68

program main
  integer(4), parameter  :: sz = 10
  real(4), dimension(sz) :: o0
  real(4), dimension(sz) :: i0
  real(4), dimension(sz) :: i1
  real(8)                :: r0, r1
  real(8)                :: min0, max0
  real(8)                :: min1, max1
  real(8)                :: min2, max2
  ! Init:
    min0 = -10
    max0 = 10
    min1 = -10
    max1 = 10
  do i=1,sz
    r0 = random_in(min0, max0)
    r1 = random_in(min1, max1)
    i0(i) = r0
    i1(i) = r1
  end do
  ! Example:
  call archr_core_pow2_f32f32(o0, i0, size(i0), i1)
  ! 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 :     33554431
           2 :            5
           3 :            0
           4 :          -72
           5 :          768
           6 :           -2
           7 :            0
           8 :           -8
           9 :            0
          10 :           -1