Skip to content

Commit

Permalink
Separated common functions to utils, maybe bad practice?
Browse files Browse the repository at this point in the history
  • Loading branch information
Irreq committed Sep 30, 2023
1 parent 8c65aca commit ca08cc9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/utils.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <stdint.h>
#include <limits.h>

float normalize_int32(int32_t value) {
return value < 0
? -((float)value) / INT_MIN
: ((float)value) / INT_MAX;
}

int32_t denormalize_int32(float normalized_value) {
return (int32_t)(normalized_value < 0
? normalized_value * INT_MIN
: normalized_value * INT_MAX);
}
8 changes: 8 additions & 0 deletions src/utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef _UTILS_H_
#define _UTILS_H_

#include <unistd.h>
float normalize_int32(int32_t value);
int32_t denormalize_int32(float normalized_value);

#endif

0 comments on commit ca08cc9

Please sign in to comment.