ldexp (Core Functions)


Import

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

Synopsis

 float archr_core_ldexp_1f32i32(const float i1, const int32_t i2);
(1)
 float archr_core_ldexp_1f32u32(const float i1, const uint32_t i2);
(2)
 double archr_core_ldexp_1f64i64(const double i1, const int64_t i2);
(3)
 double archr_core_ldexp_1f64u64(const double i1, const uint64_t i2);
(4)
 void archr_core_ldexp_f32i32(float *o0, const float *i1, size_t sz, const int32_t *i2);
(5)
 void archr_core_ldexp_f32u32(float *o0, const float *i1, size_t sz, const uint32_t *i2);
(6)
 void archr_core_ldexp_f64i64(double *o0, const double *i1, size_t sz, const int64_t *i2);
(7)
 void archr_core_ldexp_f64u64(double *o0, const double *i1, size_t sz, const uint64_t *i2);
(8)
 float ldexp(const float i1, const int32_t i2);
(1)
 float ldexp(const float i1, const uint32_t i2);
(2)
 double ldexp(const double i1, const int64_t i2);
(3)
 double ldexp(const double i1, const uint64_t i2);
(4)
 void ldexp(const float *i1, size_t sz, const int32_t *i2, float *o0);
(5)
 void ldexp(const float *i1, size_t sz, const uint32_t *i2, float *o0);
(6)
 void ldexp(const double *i1, size_t sz, const int64_t *i2, double *o0);
(7)
 void ldexp(const double *i1, size_t sz, const uint64_t *i2, double *o0);
(8)
subroutine archr_core_ldexp_1f32i32(real(4) :: r, real(4), parameter :: i1, integer(4), parameter :: i2)
(1)
subroutine archr_core_ldexp_1f32u32(real(4) :: r, real(4), parameter :: i1, integer(4), parameter :: i2)
(2)
subroutine archr_core_ldexp_1f64i64(real(8) :: r, real(8), parameter :: i1, integer(8), parameter :: i2)
(3)
subroutine archr_core_ldexp_1f64u64(real(8) :: r, real(8), parameter :: i1, integer(8), parameter :: i2)
(4)
subroutine archr_core_ldexp_f32i32(real(4), dimension(*), parameter :: i1, integer(4) :: sz, integer(4), dimension(*), parameter :: i2, real(4), dimension(*) :: o0)
(5)
subroutine archr_core_ldexp_f32u32(real(4), dimension(*), parameter :: i1, integer(4) :: sz, integer(4), dimension(*), parameter :: i2, real(4), dimension(*) :: o0)
(6)
subroutine archr_core_ldexp_f64i64(real(8), dimension(*), parameter :: i1, integer(4) :: sz, integer(8), dimension(*), parameter :: i2, real(8), dimension(*) :: o0)
(7)
subroutine archr_core_ldexp_f64u64(real(8), dimension(*), parameter :: i1, integer(4) :: sz, integer(8), dimension(*), parameter :: i2, real(8), dimension(*) :: o0)
(8)
def ldexp(i1, i2):
    return o0
(1)
function o0 = archr_core_ldexp(i1, i2)
(1)

Description

Computes the ldexp:

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

Possible Output

   0: ldexp(9.422858, 1) = 18.845716
   1: ldexp(-3.262253, -7) = -0.025486
   2: ldexp(-5.006380, -8) = -0.019556
   3: ldexp(4.945784, 9) = 2532.241211
   4: ldexp(5.106514, 6) = 326.816925
   5: ldexp(-0.338315, -6) = -0.005286
   6: ldexp(1.881994, 0) = 1.881994
   7: ldexp(-2.940464, -9) = -0.005743
   8: ldexp(-3.023084, -9) = -0.005904
   9: ldexp(8.596566, 9) = 4401.441895

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

Possible Output

   0: ldexp(-3.46646, 9) = -1774.83
   1: ldexp(0.0076237, -3) = 0.000952962
   2: ldexp(2.72348, 0) = 2.72348
   3: ldexp(8.51445, -8) = 0.0332596
   4: ldexp(-6.4343, 6) = -411.795
   5: ldexp(-3.71831, 0) = -3.71831
   6: ldexp(-7.9096, 0) = -7.9096
   7: ldexp(-4.88013, -4) = -0.305008
   8: ldexp(-8.88769, 2) = -35.5508
   9: ldexp(-2.04958, 2) = -8.19833

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 = -10
    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_ldexp_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 :   -7.81238079E-02
           2 :    5.11210442    
           3 :    2.04794109E-02
           4 :   -72.4728775    
           5 :    917.996826    
           6 :   -2.32995987    
           7 :    1.29283313E-02
           8 :   -8.93076897    
           9 :    6.68551773E-03
          10 :   -9.10816714E-03