atan2pi (Core Functions)


Import

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

Synopsis

 float archr_core_atan2pi_1f32f32(const float i1, const float i2);
(1)
 double archr_core_atan2pi_1f64f64(const double i1, const double i2);
(2)
 void archr_core_atan2pi_f32f32(float *o0, const float *i1, size_t sz, const float *i2);
(3)
 void archr_core_atan2pi_f64f64(double *o0, const double *i1, size_t sz, const double *i2);
(4)
 float atan2pi(const float i1, const float i2);
(1)
 double atan2pi(const double i1, const double i2);
(2)
 void atan2pi(const float *i1, size_t sz, const float *i2, float *o0);
(3)
 void atan2pi(const double *i1, size_t sz, const double *i2, double *o0);
(4)
template <typename Range> void atan2pi(const Range& i1, const Range& i2, Range& o0);
(5)
subroutine archr_core_atan2pi_1f32f32(real(4) :: r, real(4), parameter :: i1, real(4), parameter :: i2)
(1)
subroutine archr_core_atan2pi_1f64f64(real(8) :: r, real(8), parameter :: i1, real(8), parameter :: i2)
(2)
subroutine archr_core_atan2pi_f32f32(real(4), dimension(*), parameter :: i1, integer(4) :: sz, real(4), dimension(*), parameter :: i2, real(4), dimension(*) :: o0)
(3)
subroutine archr_core_atan2pi_f64f64(real(8), dimension(*), parameter :: i1, integer(4) :: sz, real(8), dimension(*), parameter :: i2, real(8), dimension(*) :: o0)
(4)
def atan2pi(i1, i2):
    return o0
(1)
function o0 = archr_core_atan2pi(i1, i2)
(1)

Description

Computes the Four-Quadrant Inverse Tangent in multiple of PIs:

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/atan2pi.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_atan2pi_f32f32(o1, i1, sz, i2);
  for (i = 0; i < sz; ++i) {
    printf("%4lu: atan2pi(%f, %f) = %f\n", i, (double)i1[i], (double)i2[i], (double)o1[i]);
  }
}

Possible Output

   0: atan2pi(9.422858, 1.837882) = 0.438685
   1: atan2pi(-3.262253, -7.822172) = -0.874230
   2: atan2pi(-5.006380, -8.051063) = -0.822919
   3: atan2pi(4.945784, 9.347142) = 0.154913
   4: atan2pi(5.106514, 6.345078) = 0.215706
   5: atan2pi(-0.338315, -6.329839) = -0.983003
   6: atan2pi(1.881994, 0.493357) = 0.418393
   7: atan2pi(-2.940464, -9.900811) = -0.908105
   8: atan2pi(-3.023084, -9.771577) = -0.904496
   9: atan2pi(8.596566, 9.594168) = 0.232561

#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cstddef>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <archr/core/atan2pi.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::atan2pi(i1.data(), sz, i2.data(), o1.data());
  for (i = 0; i < sz; ++i) {
    std::cout << std::setw(4) << i << ": " << "atan2pi" << "(" << i1[i] << ", " << i2[i] << ")" << " = " << o1[i] << std::endl;
  }
}

Possible Output

   0: atan2pi(-7.82005, -0.731833) = -0.529702
   1: atan2pi(-6.5429, 0.312485) = -0.484809
   2: atan2pi(-9.37116, -6.26109) = -0.687488
   3: atan2pi(5.69177, -0.783474) = 0.543542
   4: atan2pi(6.16947, -2.9262) = 0.640973
   5: atan2pi(7.46037, -9.22525) = 0.783544
   6: atan2pi(-2.36809, -6.93903) = -0.895315
   7: atan2pi(-6.72507, 4.74682) = -0.304356
   8: atan2pi(8.9037, 4.58183) = 0.348721
   9: atan2pi(-5.45268, 6.02538) = -0.234131

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_atan2pi_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 :  -0.702154636    
           2 :   0.551051497    
           3 :   0.963054538    
           4 :  -0.380287617    
           5 :   0.124525048    
           6 :  -0.447431535    
           7 :   0.803241193    
           8 :  -0.478859752    
           9 :   0.893499672    
          10 :  -0.916310072