exponentbits (Core Functions)


Import

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

Synopsis

 int32_t archr_core_exponentbits_1f32(const float i1);
(1)
 int64_t archr_core_exponentbits_1f64(const double i1);
(2)
 void archr_core_exponentbits_f32(int32_t *o0, const float *i1, size_t sz);
(3)
 void archr_core_exponentbits_f64(int64_t *o0, const double *i1, size_t sz);
(4)
 int32_t exponentbits(const float i1);
(1)
 int64_t exponentbits(const double i1);
(2)
 void exponentbits(const float *i1, size_t sz, int32_t *o0);
(3)
 void exponentbits(const double *i1, size_t sz, int64_t *o0);
(4)
template <typename Range> void exponentbits(const Range& i1, Range& o0);
(5)
subroutine archr_core_exponentbits_1f32(integer(4) :: r, real(4), parameter :: i1)
(1)
subroutine archr_core_exponentbits_1f64(integer(8) :: r, real(8), parameter :: i1)
(2)
subroutine archr_core_exponentbits_f32(real(4), dimension(*), parameter :: i1, integer(4) :: sz, integer(4), dimension(*) :: o0)
(3)
subroutine archr_core_exponentbits_f64(real(8), dimension(*), parameter :: i1, integer(4) :: sz, integer(8), dimension(*) :: o0)
(4)
def exponentbits(i1):
    return o0
(1)
function o0 = archr_core_exponentbits(i1)
(1)

Description

Computes the exponentbits:

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/exponentbits.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* o1 = (int32_t*)malloc(sz * sizeof(int32_t));

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

Possible Output

   0: exponentbits(9.422858) = 1090519040
   1: exponentbits(1.837882) = 1065353216
   2: exponentbits(-3.262253) = 1073741824
   3: exponentbits(-7.822172) = 1082130432
   4: exponentbits(-5.006380) = 1082130432
   5: exponentbits(-8.051063) = 1090519040
   6: exponentbits(4.945784) = 1082130432
   7: exponentbits(9.347142) = 1090519040
   8: exponentbits(5.106514) = 1082130432
   9: exponentbits(6.345078) = 1082130432

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

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

Possible Output

   0: exponentbits(9.42286) = 1090519040
   1: exponentbits(1.83788) = 1065353216
   2: exponentbits(-3.26225) = 1073741824
   3: exponentbits(-7.82217) = 1082130432
   4: exponentbits(-5.00638) = 1082130432
   5: exponentbits(-8.05106) = 1090519040
   6: exponentbits(4.94578) = 1082130432
   7: exponentbits(9.34714) = 1090519040
   8: exponentbits(5.10651) = 1082130432
   9: exponentbits(6.34508) = 1082130432

program main
  integer(4), parameter  :: sz = 10
  integer(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_exponentbits_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 :   1090519040
           2 :   1082130432
           3 :   1082130432
           4 :   1056964608
           5 :   1056964608
           6 :   1082130432
           7 :   1090519040
           8 :   1073741824
           9 :   1073741824
          10 :   1090519040