sqrt1pm1 (Core Functions)


Import

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

Synopsis

 float archr_core_sqrt1pm1_1f32(const float i1);
(1)
 double archr_core_sqrt1pm1_1f64(const double i1);
(2)
 void archr_core_sqrt1pm1_f32(float *o0, const float *i1, size_t sz);
(3)
 void archr_core_sqrt1pm1_f64(double *o0, const double *i1, size_t sz);
(4)
 float sqrt1pm1(const float i1);
(1)
 double sqrt1pm1(const double i1);
(2)
 void sqrt1pm1(const float *i1, size_t sz, float *o0);
(3)
 void sqrt1pm1(const double *i1, size_t sz, double *o0);
(4)
template <typename Range> void sqrt1pm1(const Range& i1, Range& o0);
(5)
subroutine archr_core_sqrt1pm1_1f32(real(4) :: r, real(4), parameter :: i1)
(1)
subroutine archr_core_sqrt1pm1_1f64(real(8) :: r, real(8), parameter :: i1)
(2)
subroutine archr_core_sqrt1pm1_f32(real(4), dimension(*), parameter :: i1, integer(4) :: sz, real(4), dimension(*) :: o0)
(3)
subroutine archr_core_sqrt1pm1_f64(real(8), dimension(*), parameter :: i1, integer(4) :: sz, real(8), dimension(*) :: o0)
(4)
def sqrt1pm1(i1):
    return o0
(1)
function o0 = archr_core_sqrt1pm1(i1)
(1)

Description

Computes the sqrt1pm1:

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

Possible Output

   0: sqrt1pm1(-7.820046) = -nan
   1: sqrt1pm1(-6.542902) = -nan
   2: sqrt1pm1(-9.371156) = -nan
   3: sqrt1pm1(5.691771) = 1.586846
   4: sqrt1pm1(6.169468) = 1.677586
   5: sqrt1pm1(7.460369) = 1.908671
   6: sqrt1pm1(-2.368092) = -nan
   7: sqrt1pm1(-6.725071) = -nan
   8: sqrt1pm1(8.903701) = 2.147015
   9: sqrt1pm1(-5.452684) = -nan

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

Possible Output

   0: sqrt1pm1(9.42286) = 2.22845
   1: sqrt1pm1(1.83788) = 0.684601
   2: sqrt1pm1(-3.26225) = -nan
   3: sqrt1pm1(-7.82217) = -nan
   4: sqrt1pm1(-5.00638) = -nan
   5: sqrt1pm1(-8.05106) = -nan
   6: sqrt1pm1(4.94578) = 1.4384
   7: sqrt1pm1(9.34714) = 2.2167
   8: sqrt1pm1(5.10651) = 1.47114
   9: sqrt1pm1(6.34508) = 1.71018

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_sqrt1pm1_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 :               NaN
           2 :               NaN
           3 :    1.47226715    
           4 :  -0.584064603    
           5 :   0.286600590    
           6 :               NaN
           7 :               NaN
           8 :    1.13946009    
           9 :    1.14147735    
          10 :    2.11349607