Commit a3dd7e00 authored by Aleksy Barcz's avatar Aleksy Barcz

round instead of nearbyint

+ more intuitive rounding mode
parent 46538ec3
......@@ -33,6 +33,7 @@
#include <string>
#include <dirent.h>
#include <assert.h>
#include <cmath>
#include <vector>
#include <sstream>
......@@ -695,7 +696,7 @@ TParam::ToIPCValue(SZBASE_TYPE value)
for (int i = 0; i < GetPrec(); i++) {
value *= 10;
}
return (SZB_FILE_TYPE) nearbyint(value);
return (SZB_FILE_TYPE) std::round(value);
}
void
......
......@@ -936,7 +936,7 @@ template<> unsigned short long_parcook_modbus_val_op<float>::val() {
}
float* f = (float*) v2;
int iv = nearbyint(*f * m_prec);
int iv = std::round(*f * m_prec);
unsigned int* pv = (unsigned int*) &iv;
m_log->log(10, "Float value: %f, int: %d, unsigned int: %u", *f, iv, *pv);
......@@ -969,7 +969,7 @@ unsigned short double_parcook_modbus_val_op::val() {
}
}
int32_t iv = nearbyint(*(double*)v * m_prec);
int32_t iv = std::round(*(double*)v * m_prec);
uint32_t* pv = (uint32_t*) &iv;
m_log->log(10, "Int value: %d, unsigned int: %u", iv, *pv);
......@@ -1004,7 +1004,7 @@ unsigned short decimal2_parcook_modbus_val_op::val() {
double v = rinteger + (rfraction / 1000.0);
int32_t iv = nearbyint(v * m_prec);
int32_t iv = std::round(v * m_prec);
uint32_t* pv = (uint32_t*) &iv;
m_log->log(10, "Int value: %d, unsigned int: %u", iv, *pv);
......@@ -1047,7 +1047,7 @@ unsigned short decimal3_parcook_modbus_val_op::val() {
double v = (10000 * r1) + r2 + (r3 / 1000.0);
int32_t iv = nearbyint(v * m_prec);
int32_t iv = std::round(v * m_prec);
uint32_t* pv = (uint32_t*) &iv;
m_log->log(10, "Int value: %d, unsigned int: %u", iv, *pv);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment