forked from parallella/pal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp_ftoi.c
33 lines (29 loc) · 818 Bytes
/
p_ftoi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <pal.h>
#define ZERO_POINT_FIVE 0x3F000000 // IEEE-754 32 bit float value for 0.5f
/**
*
* Converts the floating point values in 'a' to signed integer values.
*
* @param a Pointer to input vector, assume that no element is too close to LONG_MIN or LONG_MAX
*
* @param c Pointer to output vector
*
* @param n Size of 'a' and 'c' vector.
*
* @param p Number of processor to use (task parallelism)
*
* @param team Team to work with
*
* @return None
*
*/
void p_ftoi(const float *a, int *c, int n, int p, p_team_t team)
{
uint32_t tmp;
float rounding_value;
for(int i = 0; i < n; i++) {
tmp = ((*(uint32_t*)(a + i)) & 0x80000000) | ZERO_POINT_FIVE;
rounding_value = *((float*)&tmp);
*(c+i) = (int) (*(a+i) + rounding_value);
}
}