significants (Core Functions)


Import

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

Synopsis

 float archr_core_significants_1f32i32(const float i1, const int32_t i2);
(1)
 double archr_core_significants_1f64i64(const double i1, const int64_t i2);
(2)
 float archr_core_significants_1f32u32(const float i1, const uint32_t i2);
(3)
 double archr_core_significants_1f64u64(const double i1, const uint64_t i2);
(4)
 void archr_core_significants_f32i32(float *o0, const float *i1, size_t sz, const int32_t *i2);
(5)
 void archr_core_significants_f64i64(double *o0, const double *i1, size_t sz, const int64_t *i2);
(6)
 void archr_core_significants_f32u32(float *o0, const float *i1, size_t sz, const uint32_t *i2);
(7)
 void archr_core_significants_f64u64(double *o0, const double *i1, size_t sz, const uint64_t *i2);
(8)
 float significants(const float i1, const int32_t i2);
(1)
 double significants(const double i1, const int64_t i2);
(2)
 float significants(const float i1, const uint32_t i2);
(3)
 double significants(const double i1, const uint64_t i2);
(4)
 void significants(const float *i1, size_t sz, const int32_t *i2, float *o0);
(5)
 void significants(const double *i1, size_t sz, const int64_t *i2, double *o0);
(6)
 void significants(const float *i1, size_t sz, const uint32_t *i2, float *o0);
(7)
 void significants(const double *i1, size_t sz, const uint64_t *i2, double *o0);
(8)
subroutine archr_core_significants_1f32i32(real(4) :: r, real(4), parameter :: i1, integer(4), parameter :: i2)
(1)
subroutine archr_core_significants_1f64i64(real(8) :: r, real(8), parameter :: i1, integer(8), parameter :: i2)
(2)
subroutine archr_core_significants_1f32u32(real(4) :: r, real(4), parameter :: i1, integer(4), parameter :: i2)
(3)
subroutine archr_core_significants_1f64u64(real(8) :: r, real(8), parameter :: i1, integer(8), parameter :: i2)
(4)
subroutine archr_core_significants_f32i32(real(4), dimension(*), parameter :: i1, integer(4) :: sz, integer(4), dimension(*), parameter :: i2, real(4), dimension(*) :: o0)
(5)
subroutine archr_core_significants_f32u32(real(4), dimension(*), parameter :: i1, integer(4) :: sz, integer(4), dimension(*), parameter :: i2, real(4), dimension(*) :: o0)
(6)
def significants(i1, i2):
    return o0
(1)
function o0 = archr_core_significants(i1, i2)
(1)

Description

Computes the significants:

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/significants.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));
  int32_t* i2 = (int32_t*)malloc(sz * sizeof(int32_t));
  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] = (int32_t)rand_in((int32_t)1, (int32_t)10);
  }
  archr_core_significants_f32i32(o1, i1, sz, i2);
  for (i = 0; i < sz; ++i) {
    printf("%4lu: significants(%f, %d) = %f\n", i, (double)i1[i], i2[i], (double)o1[i]);
  }
}

Possible Output

   0: significants(-3.466457, 5) = -3.466500
   1: significants(2.723485, 9) = 2.723485
   2: significants(-6.434300, 3) = -6.430000
   3: significants(-7.909604, 3) = -7.910000
   4: significants(-8.887694, 4) = -8.888000
   5: significants(9.701183, 4) = 9.701000
   6: significants(-0.194786, 1) = -0.200000
   7: significants(6.732231, 5) = 6.732200
   8: significants(0.405202, 3) = 0.405000
   9: significants(2.318254, 6) = 2.318250

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

Possible Output

   0: significants(9.42286, 5) = 9.4229
   1: significants(1.83788, 2) = 1.8
   2: significants(-3.26225, 6) = -3.26225
   3: significants(-7.82217, 5) = -7.8222
   4: significants(-5.00638, 4) = -5.006
   5: significants(-8.05106, 1) = -8
   6: significants(4.94578, 4) = 4.946
   7: significants(9.34714, 1) = 9
   8: significants(5.10651, 9) = 5.10651
   9: significants(6.34508, 9) = 6.34508

program main
  integer(4), parameter  :: sz = 10
  real(4), dimension(sz) :: o0
  real(4), dimension(sz) :: i0
  integer(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 = 1
    max1 = 10
  do i=1,sz
    r0 = random_in(min0, max0)
    r1 = random_in(min1, max1)
    i0(i) = r0
    i1(i) = int(r1)
  end do
  ! Example:
  call archr_core_significants_f32i32(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 :   -10.0000000    
           2 :    5.11210012    
           3 :   0.660000026    
           4 :   -9.05910969    
           5 :    3.58592510    
           6 :   -2.32999992    
           7 :    7.00000000    
           8 :   -8.93080044    
           9 :    3.00000000    
          10 :   -2.00000000